結果

問題 No.2211 Frequency Table of GCD
ユーザー hiro71687khiro71687k
提出日時 2023-02-27 01:13:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,251 bytes
コンパイル時間 5,370 ms
コンパイル使用メモリ 264,836 KB
実行使用メモリ 12,692 KB
最終ジャッジ日時 2023-10-12 14:27:59
合計ジャッジ時間 16,113 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
7,940 KB
testcase_01 AC 26 ms
7,904 KB
testcase_02 AC 25 ms
7,876 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 327 ms
10,964 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 25 ms
7,852 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=double;
ld pie=3.14159265359;
ll mod=998244353;
long long inf=100000000000000001;
struct Eratosthenes {
    // テーブル
    vector<bool> isprime;

    // 整数 i を割り切る最小の素数
    vector<ll> minfactor;

    vector<ll>mobius;

    // コンストラクタで篩を回す
    Eratosthenes(ll N) : isprime(N+1, true),
                          minfactor(N+1, -1),
                          mobius(N+1,1) {
        // 1 は予めふるい落としておく
        isprime[1] = false;
        minfactor[1] = 1;

        // 篩
        for (ll p = 2; p <= N; ++p) {
            // すでに合成数であるものはスキップする
            if (!isprime[p]) continue;

            // p についての情報更新
            minfactor[p] = p;
            mobius[p]=-1;

            // p 以外の p の倍数から素数ラベルを剥奪
            for (ll q = p * 2; q <= N; q += p) {
                // q は合成数なのでふるい落とす
                isprime[q] = false;

                // q は p で割り切れる旨を更新
                if (minfactor[q] == -1) minfactor[q] = p;
                if ((q / p) % p == 0) mobius[q] = 0;
                else mobius[q] = -mobius[q];
            }
        }
    }

    // 高速素因数分解
    // pair (素因子, 指数) の vector を返す
    vector<pair<ll,ll>> factorize(ll n) {
        vector<pair<ll,ll>> res;
        while (n > 1) {
            ll p = minfactor[n];
            ll exp = 0;

            // n で割り切れる限り割る
            while (minfactor[n] == p) {
                n /= p;
                ++exp;
            }
            res.emplace_back(p, exp);
        }
        return res;
    }
    vector<ll>divisors(ll n){
        vector<ll>res({1});
        auto pf=factorize(n);
        for (auto p : pf)
        {
            ll s=(ll)res.size();
            for (ll i = 0; i < s; i++)
            {
                ll v=1;
                for (ll j = 0; j < p.second; j++)
                {
                    v*=p.first;
                    res.push_back(res[i]*v);
                }
                
            }
            
        }
        return res;
    }  
};
ll modpow(ll x, ll n) {
  if(n==0) return 1;  //再帰の終了条件

  else if(n%2==1) {
    return (x*modpow(x, n-1));  //nが奇数ならnを1ずらす
  }
  else return modpow((x*x), n/2);  //nが偶数ならnが半分になる
}
int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll>a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    Eratosthenes er(300000);
    vector<ll>memo(m+1,0);
    for (ll i = 0; i < n; i++)
    {
        vector<ll>x=er.divisors(a[i]);
        for (ll j = 0; j < x.size(); j++)
        {
            memo[x[j]]+=1;
        }
    }
    vector<ll>ans(m+1,0);
    for (ll i = m; i >=1; i--)
    {
        ll y=0;
        y=modpow(2,memo[i])+mod-1;
        y%=mod;
        for (ll j = 2; j*i<=m; j++)
        {
            y+=mod-ans[j*i];
            y%=mod;
        }
        ans[i]=y;
    }
    for (ll i =1; i <=m; i++)
    {
        cout << ans[i] << endl;
    }
    
}
0