hdu 2^x mod n = 1(同余定理+暴搜)

#include<stdio.h>
int main(){
	int n,m,i,j;
	while(~scanf("%d",&n)){
		if(n==1||n%2==0) printf("2^? mod %d = 1\n",n);
		else{
			long long m=1;
			for(i=1;;i++){
				m*=2;
				m%=n;
				if(m==1) break;
			}
			printf("2^%d mod %d = 1\n",i,n);
			}	
	}
	return 0;
} 

你可能感兴趣的:(hdu 2^x mod n = 1(同余定理+暴搜))