結果

問題 No.2176 LRM Question 1
ユーザー 👑 chro_96chro_96
提出日時 2023-01-06 21:32:57
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 1,063 ms
コンパイル使用メモリ 28,652 KB
実行使用メモリ 17,544 KB
最終ジャッジ日時 2023-08-20 14:35:10
合計ジャッジ時間 2,102 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
17,388 KB
testcase_01 AC 5 ms
17,492 KB
testcase_02 AC 36 ms
17,392 KB
testcase_03 AC 5 ms
17,312 KB
testcase_04 AC 36 ms
17,476 KB
testcase_05 AC 7 ms
17,532 KB
testcase_06 AC 7 ms
17,476 KB
testcase_07 AC 7 ms
17,524 KB
testcase_08 AC 35 ms
17,468 KB
testcase_09 AC 33 ms
17,484 KB
testcase_10 AC 31 ms
17,336 KB
testcase_11 AC 6 ms
17,292 KB
testcase_12 AC 5 ms
17,392 KB
testcase_13 AC 5 ms
17,460 KB
testcase_14 AC 35 ms
17,436 KB
testcase_15 AC 28 ms
17,416 KB
testcase_16 AC 24 ms
17,436 KB
testcase_17 AC 6 ms
17,544 KB
testcase_18 AC 5 ms
17,416 KB
testcase_19 AC 5 ms
17,268 KB
testcase_20 AC 6 ms
17,492 KB
testcase_21 AC 19 ms
17,352 KB
testcase_22 AC 6 ms
17,468 KB
testcase_23 AC 16 ms
17,464 KB
testcase_24 AC 5 ms
17,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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