結果

問題 No.2176 LRM Question 1
ユーザー tnakao0123tnakao0123
提出日時 2023-01-08 01:50:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 40,992 KB
実行使用メモリ 10,828 KB
最終ジャッジ日時 2023-08-21 14:49:23
合計ジャッジ時間 2,109 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,084 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,948 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
5,000 KB
testcase_05 AC 2 ms
5,064 KB
testcase_06 AC 2 ms
5,056 KB
testcase_07 AC 2 ms
5,040 KB
testcase_08 AC 2 ms
5,072 KB
testcase_09 AC 2 ms
5,072 KB
testcase_10 AC 2 ms
5,088 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
5,084 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 37 ms
10,828 KB
testcase_15 AC 5 ms
7,348 KB
testcase_16 AC 2 ms
5,004 KB
testcase_17 AC 2 ms
4,940 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
5,012 KB
testcase_22 AC 2 ms
5,080 KB
testcase_23 AC 2 ms
4,948 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2176.cc:  No.2176 LRM Question 1 - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_M = 1000000;

/* typedef */

typedef long long ll;

/* global variables */

int fs[MAX_M + 1], gs[MAX_M + 1];

/* subroutines */

/* main */

int main() {
  ll l, r;
  int m;
  scanf("%lld%lld%d", &l, &r, &m);

  if (l >= m) { puts("0"); return 0; }

  fs[0] = gs[0] = 1;
  int k = 1;
  for (; k < m; k++) {
    fs[k] = (ll)fs[k - 1] * k % m;
    gs[k] = (ll)gs[k - 1] * fs[k] % m;
    if (gs[k] == 0) break;
  }

  int sum = 0;
  for (int i = l; i <= r && gs[i] > 0; i++)
    sum = (sum + gs[i]) % m;

  printf("%d\n", sum);
  return 0;
}
0