結果

問題 No.2176 LRM Question 1
ユーザー 👑 OnjoujiTokiOnjoujiToki
提出日時 2023-01-07 00:41:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 2,013 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 133,860 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 17:58:12
合計ジャッジ時間 2,701 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 37 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 32 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 39 ms
4,380 KB
testcase_15 AC 30 ms
4,376 KB
testcase_16 AC 25 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 16 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 14 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
template <typename T>
struct DSU {
  std::vector<T> f, siz;
  DSU(int n) : f(n), siz(n, 1) { std::iota(f.begin(), f.end(), 0); }
  T leader(T x) {
    while (x != f[x]) x = f[x] = f[f[x]];
    return x;
  }
  bool same(T x, T y) { return leader(x) == leader(y); }
  bool merge(T x, T y) {
    x = leader(x);
    y = leader(y);
    if (x == y) return false;
    siz[x] += siz[y];
    f[y] = x;
    return true;
  }
  T size(int x) { return siz[leader(x)]; }
};

std::pair<std::vector<long long>, std::vector<int>> get_prime_factor_with_kinds(
    long long n) {
  std::vector<long long> prime_factors;
  std::vector<int> cnt;  // number of i_th factor
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      prime_factors.push_back(i);
      cnt.push_back(0);
      while (n % i == 0) n /= i, cnt[(int)prime_factors.size() - 1]++;
    }
  }
  if (n > 1) prime_factors.push_back(n), cnt.push_back(1);
  assert(prime_factors.size() == cnt.size());
  return {prime_factors, cnt};
}

void solve() {
  long long l, r, m;
  std::cin >> l >> r >> m;
  if (l >= m) {
    std::cout << 0 << '\n';
    return;
  }
  r = std::min(r, m - 1);
  long long f = 1, g = 1;
  for (long long i = 2; i < l; i++) {
    f = f * i % m;
    g = g * f % m;
  }
  long long ans = 0;
  for (long long i = l; i <= r; i++) {
    f = f * i % m;
    g = g * f % m;
    ans += g;
    ans %= m;
  }
  std::cout << ans << '\n';
}
int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int t = 1;
  // std::cin >> t;
  while (t--) solve();
  // solve();
  return 0;
}
0