1 //Accepted 228 KB 31 ms
2 #include <cstdio>
3 #include <cstring>
4 __int64 n;
5 void slove()
6 {
7 int ans;
8 __int64 m;
9 if (n%2==0 || n==1)
10 {
11 printf("2^? mod %I64d = 1\n",n);
12 return ;
13 }
14 m=1;
15 ans=0;
16 int flag=1;
17 while (flag)
18 {
19 ans++;
20 m=2*m%n;
21 if (m==1) flag=0;
22 }
23 printf("2^%d mod %I64d = 1\n",ans,n);
24 }
25 int main()
26 {
27 while (scanf("%I64d",&n)!=EOF)
28 {
29 slove();
30 }
31 return 0;
32 }
hdu1395 2^x mod n = 1
时间: 2024-11-09 05:09:51