結果

問題 No.502 階乗を計算するだけ
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2017-04-07 23:49:55
言語 Python2
(2.7.18)
結果
MLE  
実行時間 -
コード長 550 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 6,696 KB
実行使用メモリ 814,920 KB
最終ジャッジ日時 2023-09-23 03:01:54
合計ジャッジ時間 3,838 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,068 KB
testcase_01 AC 11 ms
5,836 KB
testcase_02 AC 11 ms
5,884 KB
testcase_03 AC 11 ms
5,932 KB
testcase_04 AC 11 ms
5,936 KB
testcase_05 AC 11 ms
5,836 KB
testcase_06 AC 11 ms
5,932 KB
testcase_07 AC 11 ms
5,948 KB
testcase_08 AC 11 ms
5,948 KB
testcase_09 AC 11 ms
5,920 KB
testcase_10 AC 11 ms
5,936 KB
testcase_11 AC 12 ms
5,912 KB
testcase_12 AC 11 ms
5,852 KB
testcase_13 AC 12 ms
5,864 KB
testcase_14 AC 12 ms
5,944 KB
testcase_15 AC 11 ms
6,040 KB
testcase_16 AC 11 ms
5,940 KB
testcase_17 AC 11 ms
5,944 KB
testcase_18 AC 11 ms
6,044 KB
testcase_19 AC 11 ms
5,960 KB
testcase_20 AC 11 ms
5,884 KB
testcase_21 AC 11 ms
5,832 KB
testcase_22 AC 100 ms
35,800 KB
testcase_23 AC 36 ms
13,808 KB
testcase_24 AC 71 ms
25,456 KB
testcase_25 AC 18 ms
8,040 KB
testcase_26 AC 45 ms
16,888 KB
testcase_27 AC 31 ms
12,264 KB
testcase_28 AC 40 ms
14,888 KB
testcase_29 AC 24 ms
9,756 KB
testcase_30 AC 95 ms
33,528 KB
testcase_31 AC 53 ms
18,892 KB
testcase_32 MLE -
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 #


def modinv(a, m):
    return pow(a, m - 2, m);

def factorialMod(n, modulus):
    ans=1
    if n <= modulus//2:
        #calculate the factorial normally (right argument of range() is exclusive)
        for i in range(1,n+1):
            ans = (ans * i) % modulus   
    else:
        #Fancypants method for large n
        for i in range(n+1,modulus):
            ans = (ans * i) % modulus
        ans = modinv(ans, modulus)
        ans = -1*ans + modulus
    return ans % modulus

mod = 1000000007;
k = raw_input()
print factorialMod(int(k), mod)
0