作业帮 > 综合 > 作业

ZOJ 1489 运行正确,WA,应该是求最小X地方错了,真心求改正

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/06 04:37:46
ZOJ 1489 运行正确,WA,应该是求最小X地方错了,真心求改正
ZOJ Problem Set - 14892^x mod n = 1
--------------------------------------------------------------------------------
Time Limit:1 Second Memory Limit:32768 KB
--------------------------------------------------------------------------------
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^4 mod 5 = 1
-------------------------------------------------------------------------------------------
#include
#include
int main()
{
int n,x,i,count,a;
scanf("%d",&n);
if(n%2==1)
{
a=1;
for(x=1;x
#include
#include
int main()
{
int n,x,i,count,a;
while(scanf("%d",&n)==1) // 多组输入
{
count=0; // 初始化count
if(n%2==1)
{
a=1;
for(x=1;x
再问: 已AC,非常感谢,但有一个地方不太明白。 a=a*2; a=a*2; a%=n; if(a%d==1) if(a==1) 为什么右边的就错了?