Consider the two number a < N of Coprime, A is the root of n when and only if P <φ (n) has AP mod n≠1 (φ (n) is the Euler function of N).
Also equivalent to the set AP (P <φ (n)) is equal to the simplified remainder of N.
Determines whether a (< N) is the original followed method of N:
Calculate φ (n) of the mass factor set {P1, p2, ..., PK), if Aφ (n)/pi mod n≠1, then A is the original root of N.
Such a is a total of φ (φ (n)).
http://poj.org/problem?id=1284
1#include <cstdio>2#include <cmath>3 using namespacestd;4 intN;5 intprime[ -], K;6 7 voidsolve () {8 intm = n-1;9K =0;Ten if(M%2==0){ Oneprime[k++] =2; A while(M%2==0) m/=2; - } - intMID = (int) sqrt (m); the for(inti =3; I <= mid; i + =2){ - if(m% i = =0){ -prime[k++] =i; - while(m% i = =0) m/=i; +MID = (int) sqrt (m); - } + } A if(M! =1) prime[k++] =m; at intAns = n-1; - for(inti =0; I < K; i++) ans/=Prime[i]; - for(inti =0; I < K; i++) ans *= prime[i]-1; -printf"%d\n", ans); - } - in intMain () { - while(~SCANF ("%d", &N)) solve (); to return 0; +}
View Code
poj1284 Primitive Roots