結果

問題 No.2211 Frequency Table of GCD
ユーザー HIcoderHIcoder
提出日時 2023-07-10 22:14:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,397 ms / 2,000 ms
コード長 1,414 bytes
コンパイル時間 1,264 ms
コンパイル使用メモリ 105,716 KB
実行使用メモリ 44,464 KB
最終ジャッジ日時 2023-10-10 01:25:25
合計ジャッジ時間 20,722 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 253 ms
9,276 KB
testcase_04 AC 509 ms
15,264 KB
testcase_05 AC 775 ms
20,448 KB
testcase_06 AC 501 ms
15,300 KB
testcase_07 AC 786 ms
20,732 KB
testcase_08 AC 22 ms
5,216 KB
testcase_09 AC 18 ms
4,636 KB
testcase_10 AC 49 ms
7,772 KB
testcase_11 AC 33 ms
6,048 KB
testcase_12 AC 53 ms
8,232 KB
testcase_13 AC 437 ms
13,880 KB
testcase_14 AC 508 ms
15,348 KB
testcase_15 AC 381 ms
12,708 KB
testcase_16 AC 476 ms
14,652 KB
testcase_17 AC 696 ms
19,040 KB
testcase_18 AC 1,120 ms
26,832 KB
testcase_19 AC 1,122 ms
26,412 KB
testcase_20 AC 1,131 ms
26,484 KB
testcase_21 AC 1,123 ms
26,320 KB
testcase_22 AC 1,119 ms
26,528 KB
testcase_23 AC 257 ms
9,344 KB
testcase_24 AC 1,380 ms
44,464 KB
testcase_25 AC 36 ms
5,636 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 1,065 ms
27,784 KB
testcase_28 AC 1,397 ms
44,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }




}
0