結果

問題 No.890 移調の限られた旋法
ユーザー kohei2019kohei2019
提出日時 2022-05-10 22:09:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 1,904 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 259,476 KB
最終ジャッジ日時 2023-09-25 05:55:48
合計ジャッジ時間 9,486 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
72,028 KB
testcase_01 AC 73 ms
71,472 KB
testcase_02 AC 73 ms
71,672 KB
testcase_03 AC 76 ms
72,020 KB
testcase_04 AC 73 ms
72,060 KB
testcase_05 AC 74 ms
71,460 KB
testcase_06 AC 77 ms
71,732 KB
testcase_07 AC 70 ms
71,612 KB
testcase_08 AC 73 ms
71,228 KB
testcase_09 AC 72 ms
71,652 KB
testcase_10 AC 71 ms
71,556 KB
testcase_11 AC 71 ms
71,544 KB
testcase_12 AC 73 ms
71,536 KB
testcase_13 AC 323 ms
255,840 KB
testcase_14 AC 323 ms
255,916 KB
testcase_15 AC 318 ms
255,976 KB
testcase_16 AC 313 ms
255,408 KB
testcase_17 AC 292 ms
254,748 KB
testcase_18 AC 291 ms
255,504 KB
testcase_19 AC 203 ms
188,736 KB
testcase_20 AC 161 ms
145,028 KB
testcase_21 AC 95 ms
88,320 KB
testcase_22 AC 255 ms
238,176 KB
testcase_23 AC 296 ms
255,376 KB
testcase_24 AC 204 ms
189,128 KB
testcase_25 AC 107 ms
100,784 KB
testcase_26 AC 304 ms
255,776 KB
testcase_27 AC 305 ms
255,960 KB
testcase_28 AC 232 ms
218,404 KB
testcase_29 AC 176 ms
164,444 KB
testcase_30 AC 294 ms
255,436 KB
testcase_31 AC 202 ms
188,532 KB
testcase_32 AC 278 ms
258,332 KB
testcase_33 AC 286 ms
259,376 KB
testcase_34 AC 281 ms
259,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
class NCK:
    '''
    最大値 :N
    mod
    '''
    def __init__(self,N,mod):
        self.mod = mod
        self.N = N
        self.factmod = [1,1]
        for i in range(2,self.N+1):
            self.factmod.append((self.factmod[-1]*i)%self.mod)

        self.inv = [0,1]
        for i in range(2, N + 1):
            self.inv.append((-self.inv[self.mod % i] * (self.mod // i)) % self.mod)

        self.invfact = [1,1]
        for i in range(2, N + 1):
            self.invfact.append((self.invfact[-1]*self.inv[i])%self.mod)

    def nCk(self,a,b):
        if a < b:
            return 0
        return ((self.factmod[a]*self.invfact[b]%self.mod)*self.invfact[a-b])%self.mod
    
    def invnCk(self,a,b):
        return ((self.factmod[a-b]*self.invfact[a]%self.mod)*self.factmod[b])%self.mod

def modPow(a,n,mod):#繰り返し二乗法 a**n % mod
    if n==0:
        return 1
    if n==1:
        return a%mod
    if n & 1:
        return (a*modPow(a,n-1,mod)) % mod
    t = modPow(a,n>>1,mod)
    return (t*t)%mod

def factorization(N):#素因数分解√N
    arr = []
    temp = N
    for i in range(2, int(-(-N**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([N, 1])
    return arr #[素因数、個数]


N,K = map(int,input().split())
mod =10**9+7
nck = NCK(N,mod)
ans = 0
lsp = factorization(math.gcd(K,N))
lsp2 = [i for i,j in lsp]

if lsp2==[1]:
    print(0)
    exit()

NN = len(lsp2)

for i in range(1,2**NN):
    ll = []
    for j in range(NN):
        if (i >> j) & 1:
            ll.append(lsp2[j])
    v = 1
    for l in ll:
        v *= l
    if len(ll)%2==1:
        ans += nck.nCk(N//v, K//v)
    else:
        ans -= nck.nCk(N//v, K//v)
    ans %= mod

print(ans)
0