結果

問題 No.1529 Constant Lcm
ユーザー Hideaki ItoHideaki Ito
提出日時 2021-06-04 21:48:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 575 ms / 3,000 ms
コード長 1,750 bytes
コンパイル時間 1,952 ms
コンパイル使用メモリ 178,428 KB
実行使用メモリ 10,636 KB
最終ジャッジ日時 2023-08-12 12:31:07
合計ジャッジ時間 8,956 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,736 KB
testcase_01 AC 9 ms
6,820 KB
testcase_02 AC 8 ms
6,764 KB
testcase_03 AC 7 ms
7,000 KB
testcase_04 AC 7 ms
6,972 KB
testcase_05 AC 8 ms
6,980 KB
testcase_06 AC 8 ms
6,744 KB
testcase_07 AC 8 ms
6,888 KB
testcase_08 AC 8 ms
6,772 KB
testcase_09 AC 8 ms
6,744 KB
testcase_10 AC 492 ms
10,408 KB
testcase_11 AC 181 ms
8,332 KB
testcase_12 AC 16 ms
6,780 KB
testcase_13 AC 415 ms
9,756 KB
testcase_14 AC 247 ms
9,060 KB
testcase_15 AC 285 ms
8,996 KB
testcase_16 AC 217 ms
8,496 KB
testcase_17 AC 118 ms
7,984 KB
testcase_18 AC 127 ms
7,944 KB
testcase_19 AC 266 ms
9,260 KB
testcase_20 AC 574 ms
10,608 KB
testcase_21 AC 575 ms
10,612 KB
testcase_22 AC 569 ms
10,628 KB
testcase_23 AC 549 ms
10,636 KB
testcase_24 AC 554 ms
10,612 KB
testcase_25 AC 544 ms
10,612 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:70:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   70 |     for(auto [a, v]: tmp) {
      |              ^
main.cpp:75:12: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   75 |   for(auto [a, v]: cnt) (ans *= modpow(a, v)) %= mod;
      |            ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

ll modpow(ll a, ll N) {
  ll ans = 1;
  ll tmp = a;
  while(N > 0) {
    if(N % 2 == 1) (ans *= tmp) %= mod;
    (tmp *= tmp) %= mod;
    N /= 2;
  }
  return ans;
}
template<typename T>
vector<T> smallest_prime_factors(T n) {
  vector<T> spf(n + 1);
  for(int i=0; i<=n; i++) spf[i] = i;
  for(T i=2; i*i<=n; i++) {
    if(spf[i] == i) {
      for(T j=i*i; j<=n; j+=i) {
        if(spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }
  return spf;
}

template<typename T>
vector<T> factorization(T x, vector<T>& spf) {
  vector<T> ret;
  while(x != 1) {
    ret.push_back(spf[x]);
    x /= spf[x];
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int MAX = 1000001;
  auto spf = smallest_prime_factors(MAX);
  int n; cin >> n;
  map<int, int> cnt;
  for(int i=1; i<=n-i; i++) {
    map<int, int> tmp;
    for(int a: factorization(i, spf)) {
      tmp[a]++;
    }
    for(int a: factorization(n-i, spf)) {
      tmp[a]++;
    }
    for(auto [a, v]: tmp) {
      chmax(cnt[a], v);
    }
  }
  ll ans = 1;
  for(auto [a, v]: cnt) (ans *= modpow(a, v)) %= mod;
  cout << ans << endk;
  return 0;
}
0