您的位置:首页 > 其它

hdu 1395

2012-12-06 09:16 120 查看

2^x mod n = 1

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7368 Accepted Submission(s): 2221



[align=left]Problem Description[/align]
Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.

[align=left]Input[/align]
One positive integer on each line, the value of n.

[align=left]Output[/align]
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.

[align=left]Sample Input[/align]

2
5


[align=left]Sample Output[/align]

2^? mod 2 = 1
2^4 mod 5 = 1


[align=left]Author[/align]
MA, Xiao

[align=left]Source[/align]
ZOJ Monthly, February 2003

[align=left]Recommend[/align]
Ignatius.L

#include "stdio.h"
int main()
{
int n, x, two;
while(~scanf("%d",&n))
{
if(n == 1 || n % 2 == 0){
printf("2^? mod %d = 1\n", n);
continue;
}
x = 1, two = 2;
while(two != 1)
{
two = two *2 % n;
x++;
}
printf("2^%d mod %d = 1\n", x, n);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: