3880
社区成员
#include <stdio.h>
int main()
{
int feed=0,result;
int n,i;
while (scanf("%d",&n))
{
result=2;
if (!feed)
{
feed=1;
}
else
{
printf("\n");
}
if (n<2||!(n%2))
{
printf("2^? mod 2 = 1");
}
else
{
for (i=1;result!=1;i++)
{
result*=2;
result%=n;
}
printf("2^%d mod 2 = 1",i);
}
}
return 0;
}
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int n, temp, result;
while(cin >> n)
{
if((n & 0x1) == 0 || n < 2)
cout << "2^? mod " << n << " = 1" << endl;
else
{
temp = 1;
result = 1;
while(1)
{
temp *= 2;
temp %= n;
if(temp == 1)
break;
++result;
}
cout << "2^" << result << " mod " << n << " = 1" << endl;
}
}
return 0;
}