Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 14494 Accepted Submission (s): 4484
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 Input
25
Sample Output
2^? MoD 2 = 12^4 MoD 5 = 1
#include <stdio.h>int main () {int n;while (scanf ("%d", &n)!=eof) {if (n==1| | n%2==0)//n is 1 of the situation without consideration, n is an even number of cases not considered. {printf ("2^? MoD%d = 1\n ", n); continue;} int W=2,j=1;while (w!=1) {j++;w*=2;w%=n;//has just started missing this step resulting in a commit timeout} printf ("2^%d mod%d = 1\n", j,n);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
2^X mod n = 1