/*Violent practices: enumeration starting from 2, then the violent Judgment g^ (P-1) = 1 (mod P) if and only if the exponent is P-1, set up 25 points 0.0*/#include<iostream>#include<cstdio>#include<cstdlib>#include<ctime>using namespacestd;Long LongMi (intAintMintp) { if(m==0)return 1; Long LongX=mi (a,m/2, p)%p; X=x*x%p; if(m%2==1) x=x*a%p; returnx;}intGet_root (intp) { for(intg=2; g;g++) { intX=mi (g,p-1, p), falg=0; if(x!=1)Continue; for(intI=2; i<=p-2; i++) if(Mi (g,i,p) = =1) {Falg=1; Break; } if(falg==0)returnG; }}intMain () {intp; scanf ("%d",&p); printf ("%d\n", Get_root (p)); return 0;}
/*find out all the different x-1 of the p1,p2...pm, for any 2<=a<=x-1, determine whether a is the root of x, only need to test a^ ((x-1)/p1), a^ ((x-1)/p2),... a^ ((x-1)/pm) in the number of M , whether there is a number mod x is 1, if present, a is not the original root of x, otherwise is the original root of X. O (M) *log (P-1) 100 min*/#include<iostream>#include<cstdio>#include<cstring>#defineMAXN 100010using namespacestd;intN,prime[maxn],l,f[maxn],ans[maxn],num;voidGet_prime () { for(intI=2; i<=maxn;i++) { if(!f[i]) prime[++l]=i; for(intj=1; j<=l;j++) { if(I*PRIME[J]>MAXN) Break; F[i*prime[j]]=1; if(i%prime[j]==0) Break; } }}voidGet_num () {intk=n-1; for(intI=1; i<=l;i++) { intfalg=0; while(k%prime[i]==0) {k=k/Prime[i]; Falg=1; } if(FALG) ans[++num]=Prime[i]; if(k==1) Break; }}Long LongMi (intAintMintp) { if(m==0)return 1; Long LongX=mi (a,m/2, p)%p; X=x*x%p; if(m%2==1) x=x*a%p; returnx;}intJudgeintx) { for(intI=1; i<=num;i++) if(Mi (x, (n1)/ans[i],n) = =1) return 0; return 1;}intMain () {scanf ("%d",&N); Get_prime (); Get_num (); for(intI=2; i;i++) if(judge (i)) {printf ("%d\n", i); return 0; }}
51NOD 1135 Original Root