Title: Give a positive integer n, ask if there is x, satisfy the condition 2^x mod n=1, if present, find the minimum value of x.
Analysis: 1, if the given n is 1, then there is certainly no such x;
2, if the given is even, 2 of the power to take more than an even number is definitely to the even, so also can not find;
3, if the given is an odd number, its digit number is 3, 5, 7, 9, and 2 of the power of the units of 2, 4, 6, 8, respectively-1 is 1, 3, 5, 7, that is, odd multiples can find relative, then 2 of the second power of each odd number will find a suitable power to meet test instructions.
Code:
#include <stdio.h>
int main ()
{
int n;
while (scanf ("%d", &n)!=eof)
{
if (n==1 | | n%2==0)
{
printf ("2^?") MoD%d = 1\n ", n);
}
Else
{
Int j = 1, mi=2;
while (1)
{
mi%= n;//Let min equals min to take the remainder of N, because this number to take the remaining n is 1 with the quotient is irrelevant, next only to see the remainder can be.
if (mi = = 1)
{
printf ("2^%d mod%d = 1\n", j,n);
break;
}
Mi *= 2;
j + +;
}
}
}
return 0;
}
Winter 2018 02 01 A question about modulo operation