結果

問題 No.890 移調の限られた旋法
ユーザー rlangevinrlangevin
提出日時 2023-10-10 12:30:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 976 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 79,608 KB
最終ジャッジ日時 2024-09-13 00:17:06
合計ジャッジ時間 3,621 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

def div(n):
    i = 1
    SS = set()
    while i * i <= n:
        if n % i == 0:
            SS.add(i)
            SS.add(n//i)
        i += 1
    SS.discard(1)
    return sorted(list(SS), reverse=True)    

N, K = map(int, input().split())
mod = 10 ** 9 + 7
n = N + 5
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod


from collections import *

D = defaultdict(int)
for d in div(N):
    if K % d:
        continue
    D[N // d] += comb(N // d, K // d)
    D[N // d] %= mod
    for dd in div(N // d):
        if N // d == dd:
            continue
        D[N // d] -= D[dd]
        D[N // d] %= mod

ans = 0
for k, v in D.items():
    ans += v
    ans %= mod

print(ans)
0