結果

問題 No.500 階乗電卓
ユーザー gew1fw
提出日時 2025-06-12 16:24:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 54,156 KB
最終ジャッジ日時 2025-06-12 16:24:55
合計ジャッジ時間 1,791 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def count_trailing_zeros(n):
    count = 0
    i = 5
    while i <= n:
        count += n // i
        i *= 5
    return count

def compute_factorial_mod(n, mod):
    result = 1
    for i in range(1, n + 1):
        result = (result * i) % mod
    return result

def compute_factorial(n):
    result = 1
    for i in range(1, n + 1):
        result *= i
    return result

n = int(input())

if n >= 50:
    print('000000000000')
else:
    t = count_trailing_zeros(n)
    if t >= 12:
        print('000000000000')
    else:
        mod_result = compute_factorial_mod(n, 10**12)
        log_val = math.lgamma(n + 1) / math.log(10)
        if log_val >= 12:
            s = str(mod_result).zfill(12)
            print(s)
        else:
            fact = compute_factorial(n)
            print(fact)
0