結果
| 問題 |
No.1529 Constant Lcm
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-04 21:48:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 587 ms / 3,000 ms |
| コード長 | 1,750 bytes |
| コンパイル時間 | 1,961 ms |
| コンパイル使用メモリ | 180,224 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-11-19 13:49:25 |
| 合計ジャッジ時間 | 8,728 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:70:14: warning: 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: warning: 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;
| ^
ソースコード
#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;
}