結果

問題 No.2176 LRM Question 1
ユーザー _yurimoir_yurimoir
提出日時 2023-01-06 22:45:18
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 500 bytes
コンパイル時間 3,300 ms
コンパイル使用メモリ 245,380 KB
実行使用メモリ 11,296 KB
最終ジャッジ日時 2024-05-07 22:25:39
合計ジャッジ時間 3,988 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
11,208 KB
testcase_02 AC 40 ms
11,004 KB
testcase_03 AC 4 ms
11,000 KB
testcase_04 AC 3 ms
11,120 KB
testcase_05 AC 4 ms
11,140 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 3 ms
11,192 KB
testcase_12 AC 3 ms
11,124 KB
testcase_13 AC 4 ms
11,052 KB
testcase_14 AC 41 ms
11,052 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 4 ms
11,252 KB
testcase_18 AC 3 ms
11,076 KB
testcase_19 AC 3 ms
11,004 KB
testcase_20 AC 4 ms
11,124 KB
testcase_21 AC 19 ms
11,184 KB
testcase_22 WA -
testcase_23 AC 17 ms
11,152 KB
testcase_24 AC 4 ms
11,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m;
vector<ll> memo(1000007,-1);
ll mfac(ll x){
    if(memo[x]!=-1)return memo[x];
    if(x==0)return 1;
    return memo[x]=x*mfac(x-1)%m;
}
int main(){
    ll l,r;
    cin>>l>>r>>m;
    if(l>=m){
        cout<<0<<endl;
        return 0;
    }
    ll fac_l=mfac(l);
    ll ans=fac_l;
    for(ll i=l+1;i<=min(m-1,r);i++){
        fac_l=fac_l*mfac(i)%m;
        ans+=fac_l;
        ans%=m;
    }
    cout<<ans<<endl;
    return 0;
}
0