結果

問題 No.1659 Product of Divisors
ユーザー ygd.ygd.
提出日時 2021-08-29 10:49:28
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,811 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 82,704 KB
実行使用メモリ 141,340 KB
最終ジャッジ日時 2024-05-01 21:31:52
合計ジャッジ時間 8,153 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 239 ms
129,344 KB
testcase_01 AC 250 ms
130,180 KB
testcase_02 AC 239 ms
129,136 KB
testcase_03 AC 254 ms
129,044 KB
testcase_04 AC 286 ms
130,536 KB
testcase_05 AC 424 ms
141,128 KB
testcase_06 AC 240 ms
130,284 KB
testcase_07 AC 238 ms
130,116 KB
testcase_08 AC 330 ms
131,468 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 237 ms
128,944 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

#ルートNまでひたすら割っていく。奇数だけにしても良いか。
#100000
def factorization(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==[]: #1の場合はここ
        arr.append([n, 1])
 
    return arr

def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n]*finv[r]*finv[n-r]%p

def perm(n,r,p):
  if (r < 0) or (n < r):
    return 0
  return fac[n]*finv[n-r]%p

N = 3*pow(10,6)+ 100
MOD = pow(10,9) + 7

fac = [-1]*(N+1); fac[0] = 1; fac[1] = 1 #階乗
finv = [-1]*(N+1); finv[0] = 1; finv[1] = 1 #階乗の逆元
inv = [-1]*(N+1); inv[0] = 0; inv[1] = 1 #逆元
for i in range(2,N+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD

def main():
    n,k= map(int,input().split()); 
    L = make_divisors(n)
    ans = 0
    for x in L:
        if x == 1:
            ans += 1
            continue
        PL = factorization(x)
        temp = 1
        for val,cnt in PL: #cntをどう分けるか
            temp *= cmb(cnt+k-1,k-1,MOD)
            temp %= MOD
        ans += temp
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()
0