結果

問題 No.2176 LRM Question 1
コンテスト
ユーザー chro_96
提出日時 2023-01-06 21:32:57
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 783 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 186 ms
コンパイル使用メモリ 38,464 KB
最終ジャッジ日時 2026-02-22 10:02:41
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int main () {
  long long l = 0LL;
  long long r = 0LL;
  int m = 0;
  
  int res = 0;
  
  long long ans = 0LL;
  long long fact[1000000] = {};
  long long fact_prod[1000000] = {};
  
  res = scanf("%lld", &l);
  res = scanf("%lld", &r);
  res = scanf("%d", &m);
  
  if (l >= ((long long)m)) {
    printf("0\n");
    return 0;
  }
  
  if (r >= ((long long)m)) {
    r = (long long)(m-1);
  }
  
  fact[0] = 1LL;
  for (int i = 1; i < m; i++) {
    fact[i] = (fact[i-1]*((long long)i))%((long long)m);
  }
  
  fact_prod[0] = 1LL;
  for (int i = 1; i < m; i++) {
    fact_prod[i] = (fact_prod[i-1]*fact[i])%((long long)m);
  }
  
  for (int i = (int)l; i <= ((int)r); i++) {
    ans += fact_prod[i];
  }
  
  printf("%lld\n", ans%((long long)m));
  return 0;
}
0