結果
問題 | No.2176 LRM Question 1 |
ユーザー |
|
提出日時 | 2023-01-06 21:29:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 884 bytes |
コンパイル時間 | 2,101 ms |
コンパイル使用メモリ | 210,412 KB |
最終ジャッジ日時 | 2025-02-09 23:40:33 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#pragma GCC optimize("Ofast")#include <bits/stdc++.h>using namespace std;typedef long long int ll;ll mod_pow(ll a,ll b,ll mod){a%=mod;if(b==0)return 1;if(b==1)return a;ll res=mod_pow(a,b/2,mod)%mod;res*=res; res%=mod;if(b%2)res*=a;return res%mod;}int main(){cin.tie(nullptr);ios::sync_with_stdio(false);ll L,R,M; cin >> L >> R >> M;ll res = 0;ll cur = 1;ll u = 1;for (ll i = 1; i < L; ++i) {if(L >= M) break;u *= i;u %= M;}for (ll i = L; i <= R; ++i) {if(i >= M) break;u *= i; u %= M;if(i == L){for (int j = 1; j <= L; ++j) {cur *= mod_pow(j,L+1-j,M);cur %= M;}}else{cur *= u; cur %= M;}res += cur;}cout << res%M << endl;}