def inv(x): return pow(x, MOD-2, MOD) def C(n, r): return fact[n] * inv(fact[r]) * inv(fact[n-r]) N, K = map(int, input().split()) MOD = 10**9 + 7 fact = [1] for i in range(1, 10**6): fact.append(i * fact[-1] % MOD) dp = [0] * N for i in range(1, N): if N % i == 0 and K % (N//i) == 0: dp[i] += C(i, K//(N//i)) dp[i] %= MOD j = 2 * i while j < N: if N % j == 0 and K % (N//j) == 0: dp[j] -= dp[i] dp[j] %= MOD j += i ans = 0 for i in range(1, N): ans += dp[i] ans %= MOD print(ans)