HDU杭电ACM1395 //成长日记

#include 
int main() {
	int n, x, s;
	while (~scanf("%d", &n)) {
		s = 1;
		if (n % 2 == 0 || n == 1) 
			printf("2^? mod %d = 1\n", n);
		else {
			for (x = 1; ; x++) {
				s *= 2;
				if (s % n == 1)	
					break;
				else if (s > n) 
					s %= n;				
			}
			printf("2^%d mod %d = 1\n", x, n);
		}
	}
	return 0;
}

 

你可能感兴趣的:(ACM基础篇(HDU,FAFU))