Title: http://www.lydsy.com/JudgeOnline/problem.php?id=1951
Test instructions
The puzzle: We find that modulus is a prime number, so we just need to ask for the results of the index mod 999911659-1.
This is a composite =2*3*4679*35617 so we can do it separately and then the CRT merges.
Separate direct Lucas can be.
Code:
1#include <cstdio>2 3#include <cstdlib>4 5#include <cmath>6 7#include <cstring>8 9#include <algorithm>Ten One#include <iostream> A -#include <vector> - the#include <map> - -#include <Set> - +#include <queue> - +#include <string> A at #defineINF 1000000000 - - #defineMAXN 200000+5 - - #defineMAXM 200000+5 - in #defineEPS 1e-10 - to #definell Long Long + - #definePA pair<int,int> the * #defineFor0 (i,n) for (int i=0;i<= (n); i++) $ Panax Notoginseng #defineFor1 (i,n) for (int i=1;i<= (n); i++) - the #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + A #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) the + #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) - $ #defineFor5 (N,M) for (int. i=1;i<=n;i++) for (int j=1;j<=m;j++) $ - using namespacestd; - theInlineintRead () - Wuyi { the - intx=0, f=1;CharCh=GetChar (); Wu - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} About $ while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} - - returnx*F; - A } + Const intp[5]={2,3,4679,35617,999911658}; the intN,M,FAC[MAXN],INV[MAXN]; - Inline ll Power (ll x,ll y,ll p) $ { thell t=1; the for(; y;y>>=1, x=x*x%p) the if(y&1) t=t*x%p; the returnT; - } inInlinevoidEXGCD (ll a,ll b,ll &x,ll &y) the { the if(!B) {x=1; y=0;return;} AboutEXGCD (b,a%b,x,y); the intt=x;x=y;y=t-a/b*y; the } the Inline ll Invinv (ll A,ll b) + { - ll x, y; the EXGCD (a,b,x,y);Bayi return(x%b+b)%b; the } theInlineintCintNintMintp) - { - if(n<m)return 0; the if(n<p&&m<p)returnfac[n]*inv[m]%p*inv[n-m]%p; the returnC (n/p,m/p,p) *c (n%p,m%p,p)%p; the } the - intMain () the the { the 94Freopen ("Input.txt","R", stdin); the theFreopen ("output.txt","W", stdout); the 98N=read (); M=read (); ll ans=0; Aboutm%=p[4]+1; - if(!m) {printf ("0\n");return 0;}101For0 (I,3)102 {103fac[0]=1;104For1 (j,p[i]-1) fac[j]=fac[j-1]*j%P[i]; theinv[0]=inv[1]=1;106For2 (J,2, p[i]-1) inv[j]= (p[i]/j+1) *inv[j-p[i]%j]%P[i];107For2 (J,2, p[i]-1) inv[j]=inv[j]*inv[j-1]%P[i];108ll t1=0, T2=INVINV (p[4]/p[i],p[i]);109 for(intj=1; j*j<=n;j++)if(n%j==0) the {111(T1+=c (N,j,p[i]))%=P[i]; the if(j*j==n)Continue;113(T1+=c (N,n/j,p[i]))%=P[i]; the } the(ans+= (LL) p[4]/p[i]%p[4]*t2%p[4]*t1%p[4])%=p[4]; the }117(ans+=p[4])%=p[4];118Cout<<power (m,ans,p[4]+1) <<Endl;119 - return 0;121 122}
View Code
BZOJ1951: [Sdoi2010] Ancient pig wen