#include <stdio.h>
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;
}