ICPC--1290: 2^x mod n = 1

1290: 2^x mod n = 1题目描述Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.
输入One positive integer on each line, the value of n.
输出If the minimum x exists, print a line with 2^x mod n = 1.
【ICPC--1290: 2^x mod n = 1】Print 2^? mod n = 1 otherwise.
You should replace x and n with specific numbers.
样例输入25样例输出2^? mod 2 = 12^4 mod 5 = 1代码#include #include using namespace std; int main(){int n,i,x;while(~scanf("%d",else{for(i=1,x=2;; i++,x*=2){if(x%n==1) break;x%=n;}printf("2^%d mod %d = 1\n",i,n);}}return 0;}