#include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) typedef long long ll; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; using namespace std; const int max_comb=1000000; vector fac(max_comb+1); //n! (mod M) vector ifac(max_comb+1); //k!^(-1) (mod M) ll mpow(ll x, ll n){ //x^n(mod M) ll ans = 1; while(n != 0){ if(n&1) ans = ans*x % MOD; x = x*x % MOD; n = n >> 1; } return ans; } ll minv(ll x){ return mpow( x, MOD-2 ); } ll comb(int a, int b){ // C(a,b) = a! * b!^(-1) * (a-b)^(-1) if(a == 0 && b == 0)return 1; if(a < b || a < 0)return 0; ll tmp = ifac[a-b]* ifac[b] % MOD; return tmp * fac[a] % MOD; } ll perm(int a, int b){ // P(a,b) = a! * (a-b)!^(-1) if(b == 0)return 1; if(a < b || a < 0)return 0; ll tmp = ifac[a-b] % MOD; return tmp * fac[a] % MOD; } void pre_comb() { fac[0] = 1; ifac[0] = 1; for(int i = 0; i pp; void preparePrime( int maxp ) { int i; vector a(maxp+1); for(i=2; i<=maxp; i++) { int k=i+i; while(k<=maxp) { a[k]=1; k+=i; } } for(i=2; i<=maxp; i++) { if(a[i]==0) pp.push_back( i ); } return; } void decompositPrime( ll a, vector >& vv ) { preparePrime( (int)sqrt((double)a)+1 ); int i; for(i=0; i<(int)pp.size(); i++) { int count = 0; while(a % pp[i] == 0 ) { a /= pp[i]; count ++; } if(count>0) vv.push_back( make_pair( pp[i], count ) ); if (a==1) break; } if(a>1) { vv.push_back( make_pair( a, 1 ) ); } return; } int main(int argc, char* argv[]) { int n,k; scanf("%d%d", &n, &k); int m = gcd(n,k); if(m==1) { if(n==k) { printf("1\n"); return 0; } else { printf("0\n"); return 0; } } pre_comb(); vector > vv; decompositPrime(m, vv); ll ans=0; int siz=(int)vv.size(); int i,j; for(i=0; i<(1<