def sum_of_totient(N): R = int(N**0.64) # R+1 まで s(i) を前計算 primes = Eratosthenes(R+1) res = list(range(R+1)) for p in primes: for j in range(R//p,0,-1): res[j*p] -= res[j] from itertools import accumulate res = list(accumulate(res)) # 最終的に、memo[i] = sum_of_totient(N//i) S = N//R memo = [0]*(S+1) for i in range(S,0,-1): x = N//i rx = int(x**0.5) ans = x*(x+1)//2 # 漸化式 \sum(s(N/i)) = n*(n+1)//2 を使う # floor(N/i) = c となる部分をまとめて計算 #print(ans) for c in range(1,rx): ans -= (x//c - x//(c+1))*res[c] # そうじゃない部分を個別に計算 # N//i//j = N//(i*j) for j in range(2,x//rx+1): if i*j <= S: ans -= memo[i*j] else: ans -= res[x//j] memo[i] = ans return memo[1] def Eratosthenes(N): #N以下の素数のリストを返す N+=1 is_prime_list = [True]*N m = int(N**0.5)+1 for i in range(3,m,2): if is_prime_list[i]: is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1) return [2] + [i for i in range(3,N,2) if is_prime_list[i]] n,m = map(int,input().split()) ans = 2*(sum_of_totient(n//m)-1) for i in range(n-2): ans = ans*(i+1)%1000000007 print(ans)