結果
問題 | No.1529 Constant Lcm |
ユーザー |
![]() |
提出日時 | 2021-06-04 22:17:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,901 ms / 3,000 ms |
コード長 | 2,757 bytes |
コンパイル時間 | 1,146 ms |
コンパイル使用メモリ | 106,056 KB |
実行使用メモリ | 77,316 KB |
最終ジャッジ日時 | 2024-11-19 15:20:47 |
合計ジャッジ時間 | 20,878 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#include <iostream>#include <string>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <set>#include <map>#include <queue>#include <stack>#include <list>#include <iterator>#include <cassert>#include <numeric>#include <functional>#include <ctime>#pragma warning(disable:4996)//#define ATCODER#ifdef ATCODER#include <atcoder/all>#endiftypedef long long ll;typedef unsigned long long ull;#define LINF 9223300000000000000#define LINF2 1223300000000000000#define LINF3 1000000000000#define INF 2140000000//const long long MOD = 1000000007;const long long MOD = 998244353;using namespace std;#ifdef ATCODERusing namespace atcoder;#endifll mpow(ll x, ll n) { //x^n(mod M)ll ans = 1;while (n != 0) {if (n & 1) ans = ans * x % MOD;x = x * x % MOD;n = n >> 1;}return ans;}void decompositAll(int n, vector<vector<pair<int, int>>>& dec) // n以下を全て素因数分解 例:dec[12]={(2,2),(3,1)}{dec.resize(n + 1);vector<int> f(n + 1);int i;for (i = 2; i <= n; i++) {if (f[i] == 0) {int i2 = i;while (i2 <= n) {int j = i2;while (j <= n) {f[j] = 1;if (!dec[j].empty() && dec[j].back().first == i) {dec[j].back().second++;}else {dec[j].push_back(make_pair(i, 1));}j += i2;}if ((ll)i2*i > n) break;i2 = i2 * i;}}}return;}void solve(){int n;scanf("%d", &n);vector<vector<pair<int, int>>> dec;decompositAll(n, dec);ll ans = 1;map<int, int> z;for (int i = 1; i <= n - 1; i++) {vector<pair<int, int>>& v0 = dec[i];vector<pair<int, int>>& v1 = dec[n-i];map<int,int> s0;for (int k = 0; k < (int)v0.size(); k++) {s0[v0[k].first] = v0[k].second;}for (int k = 0; k < (int)v1.size(); k++) {s0[v1[k].first]+=v1[k].second;}auto it = s0.begin();for(;it!=s0.end();++it){z[it->first] = max(z[it->first], it->second);}}auto it = z.begin();for (; it != z.end(); ++it) {int p = it->first;int num = it->second;ans = ans * mpow(p, num) %MOD;}printf("%lld\n", ans);return;}int main(){#if 1solve();#elseint T, t;scanf("%d", &T);for (t = 0; t < T; t++) {//printf("Case #%d: ", t + 1);solve();}#endifreturn 0;}