結果
問題 |
No.2081 Make a Test Case of GCD Subset
|
ユーザー |
![]() |
提出日時 | 2022-09-26 03:03:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 1,250 bytes |
コンパイル時間 | 2,098 ms |
コンパイル使用メモリ | 207,368 KB |
最終ジャッジ日時 | 2025-02-07 15:51:30 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 27 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; bool isPrime(ll x){ if(x<2) return false; else if(x==2) return true; if(x%2==0) return false; for(ll i=3;i*i<=x;i+=2){ if(x%i==0) return false; } return true; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); vector<ll> C; for(int i=2;i<100000;i++){ if(isPrime(i)) C.push_back(i); } ll m; cin>>m; if(m==0){ cout<<1<<endl; cout<<1<<endl; return 0; } priority_queue<pair<ll,ll>> que; ll t=2; ll now=1; while(t<998244353){ que.push({t-1,now}); t*=2; now++; } queue<ll> que2; while(m>0){ while(que.top().first>m) que.pop(); que2.push(que.top().second); m-=que.top().first; } ll e=que2.size(); vector<ll> D(e),E(e); rep(i,e){ D[i]=C[i]; E[i]=que2.front(); que2.pop(); } vector<ll> ANS; int np=e; for(int i=e-1;i>=0;i--){ ll x=D[i]; ANS.push_back(x); rep(j,E[i]-1){ ANS.push_back(x*C[np]); np++; } } int y=ANS.size(); cout<<y<<endl; rep(i,y){ if(i) cout<<" "; cout<<ANS[i]; } cout<<endl; return 0; }