結果

問題 No.502 階乗を計算するだけ
ユーザー tenp1729tenp1729
提出日時 2024-04-23 15:27:39
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 821 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,552 KB
実行使用メモリ 86,092 KB
最終ジャッジ日時 2024-04-23 15:27:50
合計ジャッジ時間 5,518 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
59,952 KB
testcase_01 AC 41 ms
52,244 KB
testcase_02 AC 39 ms
53,200 KB
testcase_03 AC 40 ms
53,292 KB
testcase_04 AC 39 ms
53,500 KB
testcase_05 AC 38 ms
53,048 KB
testcase_06 AC 39 ms
53,492 KB
testcase_07 AC 40 ms
52,208 KB
testcase_08 AC 40 ms
53,888 KB
testcase_09 AC 43 ms
54,344 KB
testcase_10 AC 39 ms
52,708 KB
testcase_11 AC 39 ms
53,000 KB
testcase_12 AC 39 ms
52,964 KB
testcase_13 AC 40 ms
52,420 KB
testcase_14 AC 39 ms
52,456 KB
testcase_15 AC 39 ms
52,684 KB
testcase_16 AC 38 ms
52,760 KB
testcase_17 AC 44 ms
53,108 KB
testcase_18 AC 41 ms
52,416 KB
testcase_19 AC 39 ms
52,928 KB
testcase_20 AC 39 ms
53,252 KB
testcase_21 AC 38 ms
52,552 KB
testcase_22 AC 109 ms
75,956 KB
testcase_23 AC 100 ms
76,436 KB
testcase_24 AC 91 ms
75,992 KB
testcase_25 AC 73 ms
75,796 KB
testcase_26 AC 101 ms
76,048 KB
testcase_27 AC 82 ms
75,984 KB
testcase_28 AC 102 ms
76,376 KB
testcase_29 AC 98 ms
76,460 KB
testcase_30 AC 158 ms
76,472 KB
testcase_31 AC 93 ms
75,948 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
mod = 10**9+7
small = [1, 1, 2, 6, 24, 120]


def odd_f(s: int, t: int, mod:int=10**9+7) -> int:
    if s >= t: return 1
    m = (t-2).bit_length()
    num = (t-s)//2
    if m * num < 63:
        re = s
        for x in range(s+2, t, 2):
            re = (re*x) % mod
        return re
    mid = (s+num)| 1
    u = odd_f(s, mid, mod)
    v = odd_f(mid, t, mod)
    return u*v%mod


def calc_odd(n: int) -> int:
    re = 1
    s = 3
    a = 1
    m = n.bit_length()-1
    for i in range(m-1, -1, -1):
        t = ((n>>i)+1) | 1
        a *= odd_f(s, t, mod)
        s = t
        re *= a
    return re


n = int(input())
if n <= 5:
    print(small[n])
elif n>=mod:
    print(0)
else:
    odd = calc_odd(n)
    two = n-bin(n).count("1")
    p = pow(2, two, mod)
    print((odd*p)%mod)
0