結果

問題 No.502 階乗を計算するだけ
ユーザー eroge_mastereroge_master
提出日時 2024-04-23 17:04:11
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,039 bytes
コンパイル時間 1,139 ms
コンパイル使用メモリ 29,824 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 17:04:13
合計ジャッジ時間 1,604 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 0 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 5 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 5 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 1 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 4 ms
5,376 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdint.h>

#define MODULUS 1000000007
#define INTERVAL 1000000
#define FACTORIALS_LEN 1001

uint32_t FACTORIALS[FACTORIALS_LEN] = {
    1, 641102369, 578095319, 5832229, // Continue this with your existing data
    // Complete this array as per your specific data requirements
};

typedef struct {
    uint32_t value;
} Modint;

Modint new_Modint(uint32_t value) {
    return (Modint) {value % MODULUS};
}

Modint multiply_Modint(Modint a, Modint b) {
    uint64_t temp = (uint64_t)a.value * (uint64_t)b.value;
    temp %= MODULUS;
    return new_Modint((uint32_t)temp);
}

Modint factorial_Modint(uint32_t n) {
    if (n >= MODULUS) {
        return new_Modint(0);
    }
    Modint fac = new_Modint(FACTORIALS[n / INTERVAL]);
    for (uint32_t i = n / INTERVAL * INTERVAL + 1; i <= n; i++) {
        fac = multiply_Modint(fac, new_Modint(i));
    }
    return fac;
}

int main() {
    uint32_t n;
    scanf("%u", &n);
    Modint result = factorial_Modint(n);
    printf("%u\n", result.value);
    return 0;
}
0