結果

問題 No.2176 LRM Question 1
ユーザー umezoumezo
提出日時 2023-01-06 21:33:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 2,478 ms
コンパイル使用メモリ 201,104 KB
実行使用メモリ 26,652 KB
最終ジャッジ日時 2023-08-20 14:35:38
合計ジャッジ時間 3,725 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
26,392 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 52 ms
26,564 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 53 ms
26,564 KB
testcase_05 AC 53 ms
26,632 KB
testcase_06 AC 53 ms
26,568 KB
testcase_07 AC 53 ms
26,484 KB
testcase_08 AC 53 ms
26,460 KB
testcase_09 AC 53 ms
26,564 KB
testcase_10 AC 54 ms
26,644 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 54 ms
26,484 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 52 ms
26,452 KB
testcase_15 AC 52 ms
26,512 KB
testcase_16 AC 52 ms
26,388 KB
testcase_17 AC 53 ms
26,560 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 52 ms
26,652 KB
testcase_22 AC 52 ms
26,412 KB
testcase_23 AC 53 ms
26,592 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll l,r,m;
  cin>>l>>r>>m;
  
  if(m<=l || m==1){
    cout<<0<<endl;
    return 0;
  }
  
  vector<ll> ka(1000100);
  ka[0]=1,ka[1]=1;
  for(ll i=2;i<1000100;i++) ka[i]=ka[i-1]*i%m;
  
  vector<ll> A(1000100);
  A[1]=ka[1];
  for(ll i=2;i<1000100;i++) A[i]=A[i-1]*ka[i]%m;
  
  vector<ll> S(1000100);
  S[0]=0;
  for(ll i=1;i<1000100;i++) S[i]=(S[i-1]+A[i])%m;
  
  cout<<(S[min(m-1,r)]-S[l-1]+m)%m<<endl;
  
  return 0;
}
0