結果

問題 No.1529 Constant Lcm
ユーザー simansiman
提出日時 2021-12-17 07:44:02
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,656 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 110,532 KB
実行使用メモリ 41,220 KB
最終ジャッジ日時 2023-10-12 08:48:27
合計ジャッジ時間 7,949 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,152 KB
testcase_01 AC 9 ms
5,084 KB
testcase_02 AC 7 ms
5,108 KB
testcase_03 AC 7 ms
5,172 KB
testcase_04 AC 7 ms
5,172 KB
testcase_05 AC 8 ms
5,152 KB
testcase_06 AC 7 ms
5,148 KB
testcase_07 AC 8 ms
5,192 KB
testcase_08 AC 7 ms
5,084 KB
testcase_09 AC 7 ms
5,136 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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) {
      assert(i < prime_list.size());
      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> res = prime.prime_division(a);

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

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