結果

問題 No.2176 LRM Question 1
ユーザー coder_So_heycoder_So_hey
提出日時 2023-01-06 22:48:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 944 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 56,572 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-07 22:28:47
合計ジャッジ時間 4,062 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

long long int fac(long long int n, long long int m){
    if (n > 1) {
        n *= fac(n - 1, m);
        if (n >= m) {
            n %= m;
        }
        return n;
    } else {
        return 1;
    }
}

int main(){
    long long int L, R, M;
    cin >> L >> R >> M;

    if (L >= M) {
        cout << 0 << endl;
        return 0;
    }

    long long int facto = 1, index = 2;
    while (facto != 0) {
        facto *= fac(index, M);
        if (facto >= M) {
            facto %= M;
        }
        index++;
    }

    long long int ans = 0;
    for (long long int i = L; i < index + 1; i++) {
        long long int a = 1;
        for (long long int j = 1; j <= i; j++) {
            a *= fac(j, M);
            if (a >= M) {
                a %= M;
            }
        }
        ans += a;
        if (ans >= M) {
            ans %= M;
        }
    }
    cout << ans << endl;
    return 0;
}
0