#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 # %% N, K = map(int, read().split()) D = np.gcd(N, K) # %% def cumprod(A, MOD=MOD): L = len(A) Lsq = int(L**.5 + 1) A = np.resize(A, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): A[:, n] *= A[:, n - 1] A[:, n] %= MOD for n in range(1, Lsq): A[n] *= A[n - 1, -1] A[n] %= MOD return A.ravel()[:L] def make_fact(U, MOD=MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] fact.flags.writeable = False fact_inv.flags.writeable = False return fact, fact_inv # %% U = 10 ** 6 + 10 fact, fact_inv = make_fact(U) # %% x = np.arange(1, D + 1, dtype=np.int64) div = x[D % x == 0] # %% n = N // div k = K // div dp = fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD dp # %% div = div[::-1] dp = dp[::-1] for i in range(1, len(div)): dp[i] -= dp[:i][div[:i] % div[i] == 0].sum() dp[i] %= MOD # %% answer = dp[:-1].sum() % MOD print(answer)