結果
問題 | No.1529 Constant Lcm |
ユーザー | inksamurai |
提出日時 | 2021-06-05 01:01:03 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 363 ms / 3,000 ms |
コード長 | 2,722 bytes |
コンパイル時間 | 1,320 ms |
コンパイル使用メモリ | 119,920 KB |
実行使用メモリ | 102,760 KB |
最終ジャッジ日時 | 2024-04-30 17:09:24 |
合計ジャッジ時間 | 11,116 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 312 ms
102,552 KB |
testcase_01 | AC | 315 ms
102,516 KB |
testcase_02 | AC | 315 ms
102,544 KB |
testcase_03 | AC | 307 ms
102,584 KB |
testcase_04 | AC | 312 ms
102,544 KB |
testcase_05 | AC | 312 ms
102,524 KB |
testcase_06 | AC | 320 ms
102,516 KB |
testcase_07 | AC | 319 ms
102,664 KB |
testcase_08 | AC | 309 ms
102,524 KB |
testcase_09 | AC | 310 ms
102,416 KB |
testcase_10 | AC | 354 ms
102,588 KB |
testcase_11 | AC | 330 ms
102,520 KB |
testcase_12 | AC | 309 ms
102,516 KB |
testcase_13 | AC | 347 ms
102,696 KB |
testcase_14 | AC | 336 ms
102,752 KB |
testcase_15 | AC | 340 ms
102,616 KB |
testcase_16 | AC | 330 ms
102,528 KB |
testcase_17 | AC | 315 ms
102,588 KB |
testcase_18 | AC | 313 ms
102,732 KB |
testcase_19 | AC | 330 ms
102,532 KB |
testcase_20 | AC | 350 ms
102,636 KB |
testcase_21 | AC | 352 ms
102,548 KB |
testcase_22 | AC | 344 ms
102,664 KB |
testcase_23 | AC | 352 ms
102,752 KB |
testcase_24 | AC | 363 ms
102,760 KB |
testcase_25 | AC | 357 ms
102,700 KB |
ソースコード
#include <cmath> #include <deque> #include <algorithm> #include <iterator> #include <list> #include <tuple> #include <map> #include <unordered_map> #include <queue> #include <set> #include <unordered_set> #include <stack> #include <string> #include <vector> #include <fstream> #include <iostream> #include <functional> #include <numeric> #include <iomanip> #include <stdio.h> //eolibraries #define lnf 3999999999999999999 #define inf 999999999 #define PI 3.14159265359 #define endl "\n" #define fi first #define se second #define pb push_back #define eb emplace_back #define ll long long #define all(c) (c).begin(),(c).end() #define sz(c) (ll)(c).size() #define mkp(a,b) make_pair(a,b) #define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end()) #define rsz(a,n) a.resize(n) #define pii pair <ll,ll> #define rep(i,n) for(int i = 0 ; i < n ; i++) #define drep(i,n) for(int i = n-1 ; i >= 0 ; i--) #define crep(i,x,n) for(int i = x ; i < n ; i++) #define vi vector <ll> #define vec(s) vector<s> #define rsz(a,n) a.resize(n) #define rszv(a,n,v) a.resize(n,v) #define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); //eodefine const int max_n = 1000002; using namespace std; int mod=998244353; //modarth ll binpow(ll a, ll b) { a %= mod; ll res = 1; while (b) { if (b%2) res = res * a % mod; a = a * a % mod; b /= 2; } return res % mod; } ll prod(ll a , ll b){ a%=mod; b%=mod; return ((a*b)%mod); } ll add(ll a , ll b){ a%=mod; b%=mod; return (a+b)%mod; } //modarth //numtheory primefactorization //https://yukicoder.me/problems/no/1529 vec(vec(pii)) prmfct; void fdprm(int nupto) { //glblhere vi prm; //glblhere prmfct.clear(); prmfct.resize(nupto+3,vec(pii)()); prm.resize(nupto+3,0); crep(i,2,sqrt(nupto)+1){ if(prm[i] == 0) { for(int j = i*i ; j <= nupto ; j += i) prm[j] = i; } } crep(i,2,nupto+1) if(prm[i]==0) prm[i]=i; crep(i,2,nupto+1){ int x=i,y=0,pup=0,cnt=0; while(x!=1) { y=prm[x],pup=y; if(y==0) break; cnt=0; while(y!=0 and x%y==0) {x/=y;cnt++;} prmfct[i].pb({pup,cnt}); } } } int nmp[max_n],mp[max_n]; void merg(int x,int y) { for(auto p:prmfct[x])nmp[p.fi]=0; for(auto p:prmfct[y])nmp[p.fi]=0; for(auto p:prmfct[x])nmp[p.fi]=p.se; for(auto p:prmfct[y])nmp[p.fi]+=p.se; for(auto p :prmfct[x]) mp[p.fi]=max(mp[p.fi],nmp[p.fi]); for(auto p :prmfct[y]) mp[p.fi]=max(mp[p.fi],nmp[p.fi]); } int main(){ fcin; fdprm(1000000); int n; cin>>n; crep(i,1,n) { if(i>n-i) break; merg(i,n-i); } ll ans=1; crep(i,1,max_n-3){ if(mp[i]==0)continue; ans=prod(ans,binpow(i,mp[i])); } cout << ans << "\n"; /* */ return 0; }