結果

問題 No.2527 H and W
ユーザー FromBooskaFromBooska
提出日時 2023-11-04 11:40:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,054 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 223,948 KB
最終ジャッジ日時 2023-11-04 11:41:16
合計ジャッジ時間 23,215 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,624 KB
testcase_01 AC 37 ms
53,624 KB
testcase_02 AC 1,034 ms
215,380 KB
testcase_03 AC 37 ms
53,624 KB
testcase_04 AC 1,051 ms
217,492 KB
testcase_05 AC 1,032 ms
217,492 KB
testcase_06 AC 1,031 ms
223,948 KB
testcase_07 AC 37 ms
53,624 KB
testcase_08 AC 1,003 ms
215,380 KB
testcase_09 AC 1,024 ms
215,380 KB
testcase_10 AC 1,039 ms
215,380 KB
testcase_11 AC 1,054 ms
217,492 KB
testcase_12 AC 1,012 ms
217,492 KB
testcase_13 AC 1,024 ms
217,492 KB
testcase_14 AC 1,040 ms
217,492 KB
testcase_15 AC 1,052 ms
217,492 KB
testcase_16 AC 1,037 ms
215,380 KB
testcase_17 AC 1,000 ms
215,380 KB
testcase_18 AC 1,015 ms
215,380 KB
testcase_19 AC 655 ms
146,260 KB
testcase_20 AC 717 ms
157,280 KB
testcase_21 AC 1,026 ms
215,380 KB
testcase_22 AC 1,040 ms
215,380 KB
testcase_23 AC 1,030 ms
215,380 KB
testcase_24 AC 677 ms
156,852 KB
testcase_25 AC 882 ms
182,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Kを約数の積に分解、それぞれの約数をH, Wから選ぶ組合せ数
# nCrメモ化パッケージ、約数列挙

H, W, K = map(int, input().split())
mod = 998244353

# nCrメモ化パッケージ
factorial = [1] #0分
inverse = [1] #0分
for i in range(1, max(H, W)+1):
    factorial.append(factorial[-1]*i%mod)
    inverse.append(pow(factorial[-1], mod-2, mod))
    
def nCr_fast(N, R, MOD):
    if N < R or R < 0:
        return 0
    elif R == 0 or R == N:
        return 1
    return factorial[N]*inverse[R]*inverse[N-R]%MOD

def 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]

ans = 0
divs = divisors(K)
for d1 in divs:
    d2 = K//d1
    calc = nCr_fast(H, d1, mod)*nCr_fast(W, d2, mod)
    calc %= mod
    ans += calc
    ans %= mod
print(ans)
0