#include using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long LL; typedef pair P; const LL mod=1000000007; const LL LINF=1LL<<60; const int INF=1<<30; vector fact; vector inver(2000001); LL combi(int n,int r){ if(n 0){ if(n&1){ x=x*a%mod; } a=a*a%mod; n >>= 1; } return x; } void set_combi(){ LL s=1; fact.push_back(1); for(int i=1;i<=2000000;i++){ s*=i; s%=mod; fact.push_back(s); } inver[2000000]=fpow(fact[2000000],mod-2); for(int i=1999999;i>=0;i--){ inver[i]=inver[i+1]*(i+1)%mod; } } vector divi(LL K){ vector v; for(int i=1;i*i<=K;i++){ if(K%i) continue; v.pb(i); v.pb(K/i); } sort(ALL(v)); v.erase(unique(ALL(v)),v.end()); return v; } LL gcd(LL a,LL b){ if(b>a) swap(a,b); if(a%b==0) return b; return gcd(b,a%b); } vector pdivi(LL K){ vector v; for(int i=2;i*i<=K;i++){ if(K%i) continue; v.pb(i); while(K%i==0){ K/=i; } } if(K!=1) v.pb(K); return v; } int main(){ LL n,k;cin >> n >> k; if(n==k){ puts("1"); return 0; } set_combi(); LL a = gcd(n,k); auto p = pdivi(a); LL ans = 0; for (int i = 1; i < (1<>j&1){ count++; s/=p[j]; t/=p[j]; } } if(count%2){ ans = (ans + combi(s,t)) % mod; } else{ ans = (ans - combi(s,t) + mod) % mod; } } cout << ans << endl; return 0; }