結果

問題 No.3357 eの部分和 mod 素数
コンテスト
ユーザー テナガザル
提出日時 2025-11-14 21:36:59
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5,056 ms / 10,000 ms
コード長 386 bytes
コンパイル時間 920 ms
コンパイル使用メモリ 113,600 KB
実行使用メモリ 393,916 KB
最終ジャッジ日時 2025-11-14 21:38:12
合計ジャッジ時間 61,147 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
  int p;
  cin >> p;
  long long ans = 2;
  vector<int> inv(p);
  inv[1] = 1;
  long long now = 1;
  for (int i = 2; i < p; ++i)
  {
    inv[i] = p - (long long)(p / i) * inv[p % i] % p;
    now = now * inv[i] % p;
    ans = (ans + now) % p;
  }
  cout << ans % p << endl;
}
0