結果

問題 No.1396 Giri
ユーザー kk
提出日時 2021-02-15 19:54:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 2,166 ms
コンパイル使用メモリ 206,856 KB
実行使用メモリ 7,056 KB
最終ジャッジ日時 2023-09-30 18:13:58
合計ジャッジ時間 4,855 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 164 ms
6,984 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 163 ms
6,964 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 13 ms
4,380 KB
testcase_19 AC 86 ms
5,168 KB
testcase_20 AC 117 ms
5,948 KB
testcase_21 AC 147 ms
6,676 KB
testcase_22 AC 161 ms
6,940 KB
testcase_23 AC 162 ms
6,956 KB
testcase_24 AC 163 ms
6,856 KB
testcase_25 AC 163 ms
7,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long MOD = 998244353;

class sieve {
  vector<int> f;
public:
  sieve(int n) {
    f.resize(n+1);
    for (int i = 0; i <= n; i++) f[i] = i;
    for (int i = 2; i <= n; i++) {
      if (f[i] != i) continue;
      for (int j = 2 * i; j <= n; j += i)
        f[j] = i;
    }
  }

  map<int, int> factorize(int n) {
    map<int, int> ret;
    while (n > 1) {
      int p = f[n];
      while (n % p == 0) {
        n /= p;
        ++ret[p];
      }
    }
    return ret;
  }
};

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;

  sieve s(n);

  long long ret = 1;
  int maxp = 1;
  for (int i = 1; i <= n; i++) {
    auto f = s.factorize(i);
    if (f.size() == 1) {
      int p = f.begin()->first;
      ret = ret * p % MOD;
      maxp = max(maxp, p);
    }
  }
  ret = ret * modpow(maxp, MOD-2, MOD) % MOD;
  cout << ret << endl;
  
  return 0;
}
0