結果

問題 No.890 移調の限られた旋法
ユーザー SalmonizeSalmonize
提出日時 2020-05-04 20:07:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 767 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 11,092 KB
実行使用メモリ 94,744 KB
最終ジャッジ日時 2023-09-07 03:24:43
合計ジャッジ時間 27,694 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 686 ms
86,944 KB
testcase_01 AC 700 ms
87,008 KB
testcase_02 AC 685 ms
86,916 KB
testcase_03 AC 744 ms
86,916 KB
testcase_04 AC 714 ms
86,856 KB
testcase_05 AC 687 ms
86,908 KB
testcase_06 AC 706 ms
86,944 KB
testcase_07 AC 707 ms
86,936 KB
testcase_08 AC 712 ms
86,912 KB
testcase_09 AC 685 ms
86,912 KB
testcase_10 AC 703 ms
86,948 KB
testcase_11 AC 686 ms
86,856 KB
testcase_12 AC 703 ms
86,884 KB
testcase_13 AC 712 ms
94,744 KB
testcase_14 AC 767 ms
94,712 KB
testcase_15 AC 708 ms
94,736 KB
testcase_16 AC 731 ms
94,700 KB
testcase_17 AC 720 ms
93,924 KB
testcase_18 AC 712 ms
93,936 KB
testcase_19 AC 715 ms
90,952 KB
testcase_20 AC 746 ms
89,252 KB
testcase_21 AC 697 ms
87,180 KB
testcase_22 AC 722 ms
92,892 KB
testcase_23 AC 708 ms
94,344 KB
testcase_24 AC 698 ms
91,220 KB
testcase_25 AC 702 ms
87,984 KB
testcase_26 AC 714 ms
94,416 KB
testcase_27 AC 717 ms
94,532 KB
testcase_28 AC 712 ms
91,916 KB
testcase_29 AC 701 ms
90,044 KB
testcase_30 AC 715 ms
93,960 KB
testcase_31 AC 713 ms
90,844 KB
testcase_32 AC 706 ms
93,396 KB
testcase_33 AC 721 ms
93,888 KB
testcase_34 AC 710 ms
93,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisor(n):
    ass = list()
    r = int((n+1)**0.5)
    for i in range(1, r+1):
        if n%i == 0:
            ass.append(i)
            if i*i < n:
                ass.append(n//i)
    return ass #sortされていない

def fctr1(n):
    f = list()
    r = int((n+1)**0.5)
    for i in range(2, r+1):
        if n % i == 0:
            c = 0
            while n % i == 0:
                c += 1
                n //= i
            f.append(i)
    if n > 1:
        f.append(n)
    return f

n_ = 10**6
mod = 10**9 + 7
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
    fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
    rev[i] = rev[i + 1] * (i + 1) % mod

def nCr(n, r):
    if r > n:
        return 0
    return fun[n] * rev[r] % mod * rev[n - r] % mod
    
n, k = map(int, input().split())
res = [0]*(n+1)
prl = sorted(set(fctr1(n)) & set(fctr1(k)))
div = sorted(set(divisor(n)) & set(divisor(k)))[1:]
for x in div:
    res[x] = nCr(n//x, k//x)
for p in prl:
    for i in div:
        if i*p > n: break
        res[i] = (res[i] - res[i*p]) % mod
print(sum(res) % mod)
0