結果

問題 No.890 移調の限られた旋法
ユーザー neterukunneterukun
提出日時 2019-09-20 22:43:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,997 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 87,356 KB
実行使用メモリ 161,464 KB
最終ジャッジ日時 2023-10-12 20:25:36
合計ジャッジ時間 31,163 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 798 ms
160,240 KB
testcase_01 AC 799 ms
160,372 KB
testcase_02 AC 799 ms
160,816 KB
testcase_03 AC 803 ms
160,744 KB
testcase_04 AC 804 ms
160,864 KB
testcase_05 AC 796 ms
159,972 KB
testcase_06 AC 800 ms
160,344 KB
testcase_07 AC 804 ms
160,176 KB
testcase_08 AC 798 ms
159,828 KB
testcase_09 AC 802 ms
160,484 KB
testcase_10 AC 804 ms
160,180 KB
testcase_11 AC 803 ms
160,068 KB
testcase_12 AC 801 ms
160,420 KB
testcase_13 WA -
testcase_14 AC 801 ms
160,340 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 797 ms
160,564 KB
testcase_21 AC 795 ms
159,892 KB
testcase_22 AC 802 ms
160,652 KB
testcase_23 AC 803 ms
159,972 KB
testcase_24 AC 800 ms
160,436 KB
testcase_25 AC 799 ms
160,424 KB
testcase_26 WA -
testcase_27 AC 799 ms
160,812 KB
testcase_28 AC 801 ms
160,284 KB
testcase_29 AC 794 ms
160,148 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class Combination:
    '''MOD上の
    計算量:階乗・逆元テーブルの作成O(N)
    nCkを求めるO(1)'''

    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [pow(self.fact[i], MOD - 2, MOD) for i in range(n + 1)]
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD


def make_divisors(n):
    """自然数nの約数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 12 -> [1, 2, 3, 4, 6, 12]
    """
    divisors = []
    for k in range(1, int(n**0.5) + 1):
        if n % k == 0:
            divisors.append(k)
            if k != n // k:
                divisors.append(n // k)
    divisors = sorted(divisors)
    return divisors


def gcd(a, b):
    """a, bの最大公約数(greatest common divisor:GCD)を求める"""
    if b == 0:
        return a
    return gcd(b, a%b)


n, k = map(int, input().split())
MOD = 10**9 + 7
comb = Combination(10**6, MOD)

gcd_nk = gcd(n, k)
div_list = make_divisors(gcd_nk)

li = []
for num in div_list:
    if num == 1:
        continue
    total = n // num
    selected = k // num
    tmp = comb.combination(total, selected)
    li.append((total, tmp))
    
ans = 0
for i in range(len(li)):
    ans += li[i][1]
    ans %= MOD
    for j in range(i):
        if li[j][0] % li[i][0] == 0:
            ans -= li[i][1]
            ans %= MOD
print(ans)
          
0