hdu1395 2^x mod n = 1

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1395


#include <stdio.h>

int main()
{
	int n,i,x;
	while(scanf("%d",&n)!=EOF)
	{
		if((n&1)==0)
		{
			printf("2^? mod %d = 1\n",n);
			continue;
		}
		x=1;
		i=1;
		while((x=x<<1)%n!=1)
		{
			++i;
			x%=n;
			if(i>5000)
				break;
		}
		if(i>5000)
			printf("2^? mod %d = 1\n",n);
		else
			printf("2^%d mod %d = 1\n",i,n);
	}
	return 0;
}


你可能感兴趣的:(hdu1395 2^x mod n = 1)