結果

問題 No.502 階乗を計算するだけ
ユーザー kimiyukikimiyuki
提出日時 2017-04-18 16:11:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 825 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 33,992 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-26 13:15:09
合計ジャッジ時間 11,222 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 880 ms
4,376 KB
testcase_33 TLE -
testcase_34 AC 647 ms
4,376 KB
testcase_35 AC 319 ms
4,376 KB
testcase_36 TLE -
testcase_37 AC 804 ms
4,380 KB
testcase_38 TLE -
testcase_39 TLE -
testcase_40 AC 142 ms
4,376 KB
testcase_41 TLE -
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:30:5: 警告: ‘int main(int)’ は 0 個または 2 個の引数のみとります [-Wmain]
   30 | int main(int i) {
      |     ^~~~

ソースコード

diff #

#pragma GCC optimize "O3"
#pragma GCC target "avx"
#include <stdio.h>
using ll = long long;
constexpr int mod = 1e9+7;
int fact(int n) {
    ll x[8];
    for (int j = 0; j < 8; ++ j) {
        x[j] = 1;
    }
    for (ll i = 0; i+7 < n; i += 8) {
        x[0] = x[0] * (i+1) % mod;
        x[1] = x[1] * (i+2) % mod;
        x[2] = x[2] * (i+3) % mod;
        x[3] = x[3] * (i+4) % mod;
        x[4] = x[4] * (i+5) % mod;
        x[5] = x[5] * (i+6) % mod;
        x[6] = x[6] * (i+7) % mod;
        x[7] = x[7] * (i+8) % mod;
    }
    int y = 1;
    for (int j = 0; j < 8; ++ j) {
        y = y *(ll) x[j] % mod;
    }
    for (int i = n / 8 * 8; i < n; ++ i) {
        y = y *(ll) (i+1) % mod;
    }
    return y;
}
int main(int i) {
    ll n; scanf("%lld",&n);
    printf("%d\n", n >= mod ? 0 : fact(n));
    return 0;
}
0