SIZE=1000000; MOD=10**9+7 #998244353 #ここを変更する SIZE += 1 inv = [0]*SIZE # inv[j] = j^{-1} mod MOD fac = [0]*SIZE # fac[j] = j! mod MOD finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD inv[1] = 1 fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2,SIZE): inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD fac[i] = fac[i-1]*i%MOD finv[i]= finv[i-1]*inv[i]%MOD def choose(n,r): # nCk mod MOD の計算 if 0 <= r <= n: return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD else: return 0 from math import gcd def divisor_list(N): #約数のリスト if N == 1: return [1] res = [] for i in range(1,N): if i*i >= N: break if N%i == 0: res.append(i) res.append(N//i) if i*i == N: res.append(i) return sorted(res) n,k = [int(i) for i in input().split()] g = gcd(n,k) if g == 1: print(0) exit() div = divisor_list(n) div = [i for i in div if g%i==0] d = {i:choose(n//i,k//i) for i in div} d[1] = 0 #print(d) for i in reversed(div): for j in div: if j%i == 0 and i != j: d[i] -= d[j] d[i] %= MOD #print(d) print(-d[1]%MOD)