結果

問題 No.500 階乗電卓
ユーザー gew1fw
提出日時 2025-06-12 21:29:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 52,608 KB
最終ジャッジ日時 2025-06-12 21:30:17
合計ジャッジ時間 2,154 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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