#include<iostream> #include<cmath> using namespace std; const int maxn = 10001; bool isprime[maxn]; int prime[1230]; int factor[33]; //涮素数1-n int getprime(int n) { int i, j, k = 0; int s, e = (int)sqrt(n*1.0) + 1; memset(isprime, true, sizeof(isprime)); isprime[0] = isprime[1] = false; prime[k++] = 2; for(i=4; i<n; i+=2) isprime[i] = false; for(i=3; i<n; i+=2) { if(isprime[i]) { prime[k++] = i; for(s=i*2, j=i*i; j<n; j+=s) { isprime[j] = false; } } } for(; i<n; i+=2) { if(isprime[i]) prime[k++] = i; } return k; } int euler(int x) { int ret = x; for(int i=2; i<(int)(sqrt(x*1.00)+1); i++) { if(x%i==0) { ret = ret/i*(i-1); while(x%i==0) ret /= i; } } if(x > 1) ret = ret/x*(x-1); return ret; } int spilt(int x, int k) { int j = 0; for(int i=0; i<k; i++) { if(x%prime[i]==0) { factor[j++] = prime[i]; while(x%prime[i]==0) x /= prime[i]; } } return j; } int solve(int a, int n, int k) { int phi = euler(n); int pos = spilt(phi, k); for(int i=0; i<pos; i++) { if((int)(pow(a, factor[i]))%n==1) return factor[i]; } return phi; } int main() { int a, n; int k = getprime(maxn); //printf("%d/n", k); while(scanf("%d%d", &a, &n)!=EOF) { int ret = solve(a, n, k); printf("%d/n", ret); } return 0; }