結果

問題 No.890 移調の限られた旋法
ユーザー SalmonizeSalmonize
提出日時 2020-05-04 16:14:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,147 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 105,776 KB
最終ジャッジ日時 2023-09-06 18:03:12
合計ジャッジ時間 32,150 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 685 ms
86,500 KB
testcase_01 AC 682 ms
86,900 KB
testcase_02 AC 710 ms
86,848 KB
testcase_03 AC 693 ms
86,840 KB
testcase_04 AC 693 ms
86,932 KB
testcase_05 AC 690 ms
87,048 KB
testcase_06 AC 695 ms
86,840 KB
testcase_07 AC 696 ms
86,388 KB
testcase_08 AC 685 ms
86,916 KB
testcase_09 AC 723 ms
86,856 KB
testcase_10 AC 683 ms
86,968 KB
testcase_11 AC 688 ms
87,024 KB
testcase_12 AC 690 ms
86,824 KB
testcase_13 WA -
testcase_14 AC 954 ms
105,616 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 763 ms
93,276 KB
testcase_21 AC 725 ms
88,160 KB
testcase_22 AC 899 ms
101,196 KB
testcase_23 AC 902 ms
104,456 KB
testcase_24 AC 838 ms
97,128 KB
testcase_25 AC 719 ms
89,252 KB
testcase_26 WA -
testcase_27 AC 976 ms
104,980 KB
testcase_28 AC 847 ms
98,852 KB
testcase_29 AC 794 ms
94,664 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisor(n):
    ass = []
    for i in range(1, int((n+1)**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i*i < n:
                ass.append(n//i)
    return ass #sortされていない
    
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int((n+1)**0.5)+1):
        if is_prime[i]:
            for j in range(i *2, n + 1, i):
                is_prime[j] = False
    res = [i for i in range(n+1) if is_prime[i]]
    return res

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)
for x in set(divisor(n)) & set(divisor(k)):
    res[x] = nCr(n//x, k//x)
res[1] = 0
prl = primes(n)
for i in range(n, -1, -1):
    if res[i]:
        for p in prl:
            if i*p > n: break
            res[i] -= res[i*p]
print(sum(res))
0