結果

問題 No.1529 Constant Lcm
ユーザー simansiman
提出日時 2021-12-17 08:03:03
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 902 ms / 3,000 ms
コード長 1,900 bytes
コンパイル時間 3,671 ms
コンパイル使用メモリ 110,000 KB
実行使用メモリ 39,920 KB
最終ジャッジ日時 2023-10-12 09:06:35
合計ジャッジ時間 13,665 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,152 KB
testcase_01 AC 8 ms
5,120 KB
testcase_02 AC 7 ms
5,180 KB
testcase_03 AC 7 ms
5,116 KB
testcase_04 AC 7 ms
5,180 KB
testcase_05 AC 7 ms
5,156 KB
testcase_06 AC 7 ms
5,164 KB
testcase_07 AC 7 ms
5,100 KB
testcase_08 AC 7 ms
5,172 KB
testcase_09 AC 7 ms
5,128 KB
testcase_10 AC 798 ms
36,680 KB
testcase_11 AC 290 ms
17,552 KB
testcase_12 AC 18 ms
5,364 KB
testcase_13 AC 673 ms
32,192 KB
testcase_14 AC 405 ms
22,592 KB
testcase_15 AC 442 ms
23,580 KB
testcase_16 AC 342 ms
19,356 KB
testcase_17 AC 176 ms
12,800 KB
testcase_18 AC 190 ms
13,248 KB
testcase_19 AC 423 ms
23,016 KB
testcase_20 AC 899 ms
39,896 KB
testcase_21 AC 898 ms
39,844 KB
testcase_22 AC 892 ms
39,880 KB
testcase_23 AC 902 ms
39,920 KB
testcase_24 AC 890 ms
39,880 KB
testcase_25 AC 873 ms
39,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

class Prime {
public:
  vector<ll> prime_list;
  const ll MAX_N = 1000000;

  Prime() {
    bool checked[MAX_N + 1];
    memset(checked, false, sizeof(checked));

    for (ll i = 2; i <= MAX_N; ++i) {
      if (!checked[i]) {
        prime_list.push_back(i);

        for (ll j = i * i; j <= MAX_N; j += i) {
          checked[j] = true;
        }
      }
    }
  }

  map<ll, int> prime_division(ll n) {
    map<ll, int> res;

    for (ll i = 0; prime_list[i] <= sqrt(n); ++i) {
      ll p = prime_list[i];

      while (n % p == 0) {
        res[p]++;
        n /= p;
      }
    }

    if (n != 1) {
      res[n] = 1;
    }

    return res;
  }

  bool is_prime(ll n) {
    if (n <= 1) return false;

    for (int i = 0; i < prime_list.size(); ++i) {
      if (n % prime_list[i]) return false;
    }

    return true;
  }
};

int main() {
  ll N;
  cin >> N;
  Prime prime;
  vector<int> counter(N + 1, 0);
  map<ll, bool> checked;

  for (ll i = 1; i <= N - 1; ++i) {
    ll a = i * (N - i);
    if (checked[a]) continue;
    checked[a] = true;
    map<ll, int> res1 = prime.prime_division(i);
    map<ll, int> res2 = prime.prime_division(N - i);
    map<ll, int> res;

    for (auto e : res1) {
      res[e.first] += e.second;
    }

    for (auto e : res2) {
      res[e.first] += e.second;
    }

    for (auto e : res) {
      counter[e.first] = max(counter[e.first], e.second);
    }
  }

  ll ans = 1;
  for (ll i = 1; i < N; ++i) {
    if (counter[i] == 0) continue;
    ll p = 1;
    for (int j = 0; j < counter[i]; ++j) {
      p *= i;
      p %= MOD;
    }
    ans *= p;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
0