Give a number n, find the minimum x that satisfies 2^x mod n = 1.
Input
One positive integer on each line, the value of n.
Output
If 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
2
5
Sample Output
2^? mod 2 = 1
2^4mod 5 = 1
#include<stdio.h>
int main()
{
long n;
while(scanf("%ld",&n)!=EOF)
{
if(n%2==0||n==1)
{
printf("2^? mod %ld = 1/n",n);
continue ;
}
long x=2;
long m=2;
for(x=2;;x++)
{
m=2*m%n;
if(m==1)
break;
}
printf("2^%ld mod %ld = 1/n",x,n);
}
return 0;
}