Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 13345 Accepted Submission (s): 4146
Problem descriptiongive a number n, find the minimum x (x>0) that satisfies 2^x mod n = 1.
Inputone positive integer on each line, the value of N.
Outputif the minimum x exists, print a line with 2^x mod n = 1.
Print 2^? MoD n = 1 otherwise.
You should replace x and n with specific numbers.
Sample Input25
Sample output2^? MoD 2 = 12^4 MoD 5 = 1
Authorma, Xiao
#include <cstdio> #include <cmath>int powermod (int a,int b,int c)//fast power { int ans=1; if (a%c==0) return 0; a=a%c; while (b) { if (b&1) ans=ans*a%c; a=a*a%c; b>>=1; } return ans;} int main () { int i,n; The odd number except 11 has the result, the even number must have no result while (~SCANF ("%d", &n)) { if (n%2==0| | N==1)//2^x dual number to find the remainder result is even, not 1 1 when the result does not exist {printf ("2^? MoD%d = 1\n ", n); continue;} for (i=1;; i++)//For 2^X mod N, when 1<=i<=n can get all the remainder results if (powermod (2,i,n) ==1) { printf ("2^%d mod%d = 1\ n ", i,n); Break;}}}
2^X mod n = 1