August 2019 Training (II)

Today exam, cheat points cheat points. . .

T3 is a bit like 3823 on BZOJ

Original title:

Dingqingxinwu (bzoj 3823 ) 
the Description 
say that programmers can not find the sister, but no one knows, even Sansei stone engraved also belong to a small sum of E. 

That day, the small E exhausted his life savings, the sister a gift unusual token of love. It was a little 

small cubes, but through it, you can see the past, can Dongche secret. 

This keepsake as if a deep eye. When it is seen through the deceptively simple appearance, but deep inside is the most 

tapping the human soul. As expected, the sister and it was attracted by the beauty of this keepsake beyond space. 

"Easy Tai Chi is two appearances, two appearances of Health four images, four images and raw gossip., Set good and bad gossip, good and bad students great cause." 

Motto has been a perfect interpretation on it. 

Yes, this is a hypercube. 

Small E told the sister, also his affection as deep as this keepsake. Now sister wanted to know, her love for small E 

What sort of meaning ? 

We know jog into a line, the line move into the surface, the surface moving adult ...... that is n-dimensional hypercube can be seen by the n - 1 dimensional super 

cube direction perpendicular to its three-dimensional pattern in all directions rib translation obtained. 

We can point regarded as 0 -dimensional hypercube, it will be seen as a straight 1 -dimensional hypercube, a square will be seen as 2 -dimensional super 

cube ...... and so on. 

Any n-dimensional hypercube (n >0 ) are a low-dimensional hypercube elements: its n- . 1 dimensional surface 

is an n- - . 1 -dimensional hypercube, it n- 2 -dimensional edge n- is a 2 -dimensional hypercube, it n- 3 -dimensional element is N- 3 -dimensional 

hypercube ...... 

little E is the affection for his sister's token of love --K-dimensional hypercube, contains elements of each dimension of a 

number. Since the number of elements may be large, only outputs each dimension of the elements it contains and the number of modulo P XOR. 

 

Input 
two integers K, P, see the title described. 

 

 

Output 
a non-negative integer representing the elements of each dimension of Dingqingxinwu E contained small number of modulo P and XOR. Note 

meaning: exclusive and may be greater than or P. 

 

 

The Input the Sample 
INPUT . 1 
. 3  . 7 

the Input 2 

. 4  2333 

the Input . 3 

12 is  7723 
the Sample the Output 
Output1 

. 3

The Output 2 

33 is 

the Output . 3 

360 

Hint 
interpretation Sample 2: 
a three-dimensional hypercube comprising . 8 zero-dimensional element, 12 is one-dimensional elements . 6 two-dimensional element, a three-dimensional 

elements, the mold 7 after respectively 1 , 5 , 6 , 1 , and the exclusive oR is 1 ^ 5 ^ 6 ^ 1 = 3 .
View Code
Ultra consider each n-dimensional cube k-dimensional element of "diagonal" is selected from n-dimensional vector of k dimensions, each dimension is +1 or -1, the answer is C (n, k) * 2 ^ k , after the inverse element may be pre-O (n). 
However, due to be p <n, it may be required (b * p) ^ (- 1), this is no inverse, so that the current maintenance cnt p There are several answers, but also pay attention inverse is rev [tmp% p ].
Code
 
 
#include<cstdio>
#include<iostream>

#define ll long long
#define N 10000010
using namespace std;
int n,p;lon inv[N]; void getinv() { int t=min(n,p-1); inv[1]=1; for(int i=2;i<=t;i++) inv[i]=inv[p%i]*(p-p/i)%p; }
ll poww(lon a,
int b) { ll ans=1; while(b) { if(b&1) ans=ans*a%p; a=a*a%p;b>>=1; } return ans%p; }
int main() { scanf("%d%d",&n,&p); if(p==2) { printf("1\n"); return 0; } getinv(); ll ans=poww(2,n);   ll sum=ans,cnt=0; for(int i=1;i<=n;i++) { int tmp=n-i+1; while(tmp%p==0) { cnt++; tmp/=p; } ans=ans*tmp%p; tmp=i; while(tmp%p==0)     { cnt--;     tmp/=p;     } ans=ans*inv[tmp%p]%p; ans=ans*inv[2]%p; sum^=cnt?0:ans; } printf("%d\n",sum); return 0; }

 

2019-08-02 22:07:00

Guess you like

Origin www.cnblogs.com/plzplz/p/11291486.html