結果
問題 | No.2211 Frequency Table of GCD |
ユーザー |
|
提出日時 | 2023-07-10 22:14:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,382 ms / 2,000 ms |
コード長 | 1,414 bytes |
コンパイル時間 | 896 ms |
コンパイル使用メモリ | 103,220 KB |
最終ジャッジ日時 | 2025-02-15 09:37:39 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include<iostream> #include<set> #include<algorithm> #include<vector> #include<string> #include<set> #include<map> #include<numeric> #include<queue> #include<cmath> using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair<int,int> P; typedef pair<int,P> PP; const ll MOD=998244353; const double PI=acos(-1); ll mod_pow(ll x,ll y,ll mod){ ll res=1; while(y>0){ if(y&1){ res*=x; res%=mod; } x*=x; x%=mod; y/=2; } return res; } int main(){ ll N,M; cin>>N>>M; vector<ll> A(N); for(int i=0;i<N;i++){ cin>>A[i]; } vector<vector<int>> d(M+1); for(int i=0;i<N;i++){ for(ll c=1;c*c<=A[i];c++){ if(A[i]%c==0){ d[c].push_back(i); if(A[i]/c!=c){ d[A[i]/c].push_back(i); } } } } vector<ll> ans(M+1,0); for(int m=M;m>=1;m--){ ans[m]=mod_pow(2,d[m].size(),MOD)-1;//空集合を除いた ans[m]+=MOD; ans[m]%=MOD; } /* for(int m=1;m<=M;m++){ cout<<"ans["<<m<<"]="<<ans[m]<<endl; } */ for(int m=M;m>=1;m--){ for(int t=2*m;t<=M;t+=m){ ans[m]-=ans[t]; ans[m]+=MOD; ans[m]%=MOD; } } for(int m=1;m<=M;m++){ cout<<ans[m]<<endl; } }