結果

問題 No.2211 Frequency Table of GCD
ユーザー nagisa5101nagisa5101
提出日時 2023-03-27 18:43:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,307 ms / 2,000 ms
コード長 1,869 bytes
コンパイル時間 5,587 ms
コンパイル使用メモリ 269,424 KB
実行使用メモリ 7,204 KB
最終ジャッジ日時 2023-10-19 17:45:45
合計ジャッジ時間 21,983 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 243 ms
5,356 KB
testcase_04 AC 448 ms
5,620 KB
testcase_05 AC 671 ms
6,148 KB
testcase_06 AC 450 ms
5,884 KB
testcase_07 AC 695 ms
6,412 KB
testcase_08 AC 20 ms
4,368 KB
testcase_09 AC 16 ms
4,368 KB
testcase_10 AC 44 ms
4,564 KB
testcase_11 AC 29 ms
4,368 KB
testcase_12 AC 48 ms
4,564 KB
testcase_13 AC 392 ms
5,356 KB
testcase_14 AC 452 ms
5,884 KB
testcase_15 AC 350 ms
5,620 KB
testcase_16 AC 425 ms
5,884 KB
testcase_17 AC 611 ms
6,148 KB
testcase_18 AC 984 ms
7,204 KB
testcase_19 AC 982 ms
7,204 KB
testcase_20 AC 980 ms
7,204 KB
testcase_21 AC 981 ms
7,204 KB
testcase_22 AC 987 ms
7,204 KB
testcase_23 AC 252 ms
5,620 KB
testcase_24 AC 1,307 ms
7,204 KB
testcase_25 AC 24 ms
4,828 KB
testcase_26 AC 2 ms
4,368 KB
testcase_27 AC 965 ms
7,204 KB
testcase_28 AC 1,306 ms
7,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace atcoder;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, n, m) for (int i = n; i < (int)(m); i++)
#define repll2(i, n, m) for (long long i = n; i < (long long)(m); i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vvvl=vector<vvl>;
using vld=vector<ld>;
using vvld=vector<vld>;

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

const double PI = acos(-1);
//const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=(1LL<<60);
const int INF2=(1<<30);
//using mint=modint1000000007;
using mint=modint998244353;

/*  divisor(n)
    入力:整数 n
    出力:nのすべての約数
    計算量:O(√n)
*/
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n,m;cin>>n>>m;
    vl arr(n);
    vl cnt(m+1,0);
    //cnt[i]=(arrのうち、iで割り切れるものの個数)
    rep(i,n){
        cin>>arr[i];
        auto d=divisor(arr[i]);
        for(auto v:d)cnt[v]++;
    }
    vector<mint> ans(m+1);
    for(int i=m;i>=1;i--){
        ans[i]=mint(2).pow(cnt[i]);
        for(int j=2;j*i<=m;j++)ans[i]-=ans[j*i];
        ans[i]--;
    }
    rep(i,m)cout<<ans[i+1].val()<<endl;
    return 0;
}
0