結果

問題 No.2211 Frequency Table of GCD
ユーザー Ujjwal RanaUjjwal Rana
提出日時 2023-02-10 22:30:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 3,221 bytes
コンパイル時間 4,177 ms
コンパイル使用メモリ 252,360 KB
実行使用メモリ 9,388 KB
最終ジャッジ日時 2023-09-22 01:12:43
合計ジャッジ時間 6,976 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 21 ms
7,460 KB
testcase_04 AC 26 ms
6,760 KB
testcase_05 AC 35 ms
7,844 KB
testcase_06 AC 28 ms
7,464 KB
testcase_07 AC 38 ms
8,328 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 13 ms
4,432 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 13 ms
4,380 KB
testcase_13 AC 24 ms
6,484 KB
testcase_14 AC 29 ms
7,812 KB
testcase_15 AC 24 ms
7,372 KB
testcase_16 AC 28 ms
7,828 KB
testcase_17 AC 33 ms
7,588 KB
testcase_18 AC 47 ms
9,348 KB
testcase_19 AC 48 ms
9,388 KB
testcase_20 AC 49 ms
9,076 KB
testcase_21 AC 49 ms
9,172 KB
testcase_22 AC 49 ms
9,140 KB
testcase_23 AC 23 ms
7,580 KB
testcase_24 AC 44 ms
9,348 KB
testcase_25 AC 15 ms
4,768 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 44 ms
9,308 KB
testcase_28 AC 43 ms
9,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 

#define endl '\n'
typedef long long ll;
#define mod1 (ll)998244353
#define int ll
#define pll pair<ll,ll>
typedef long double lb;
typedef tree<
pair<ll, ll>,
null_type,
less<pair<ll, ll>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
#define eps (lb)(1e-9)
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// Operator overloads
template<typename T1, typename T2> // cin >> pair<T1, T2>
istream& operator>>(istream &istream, pair<T1, T2> &p) { return (istream >> p.first >> p.second); }

template<typename T> // cin >> vector<T>
istream& operator>>(istream &istream, vector<T> &v)
{
    for (auto &it : v)
        cin >> it;
    return istream;
}

template<typename T1, typename T2> // cout << pair<T1, T2>
ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { return (ostream << p.first << " " << p.second); }
template<typename T> // cout << vector<T>
ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; }

// Utility functions
template <typename T>
void print(T &&t)  { cout << t << "\n"; }
template <typename T, typename... Args>
void print(T &&t, Args &&... args)
{
    cout << t << " ";
    print(forward<Args>(args)...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(ll p){ // gives random number in [0,p]

 return uniform_int_distribution<ll>(1<<19, p)(rng);
}
ll power(ll a, ll b, ll c=mod1){
     if(a==0){
         return 0;}
     else if(b==0||a==1){
         return 1;}
     ll p=power(a,b/2,c);
     p*=p; p%=c;
     if(b%2){p*=a;} p%=c;
     return p;}
ll modinv(ll a, ll c=mod1){
     return power(a,c-2,c);
}
ll n,m;
vector<ll>freq,dp,cnt;
void solve();
signed main() {
io;
ll t=1,n=1;
// cin>>t;
while (t--){
     solve();
    }
     return 0;
}
void solve(){
    cin>>n>>m;
    freq.resize(m+1);
    freq=vector<ll>(m+1,0);
    dp=cnt=freq;
    vector<ll>v(n);
    cin>>v;
    for(auto i:v){freq[i]++;}
    for(ll i(1);i<=m;++i){
        for(ll j(i);j<=m;j+=i){
            dp[i]+=freq[j];
        }
    } 
    // cout<<freq<<endl;
    // cout<<dp<<endl;
    for(ll i(m);i>0;--i){
        cnt[i]=power(2,dp[i])-1;
        for(ll j(2*i);j<=m;j+=i){
            cnt[i]-=cnt[j];
        }
        cnt[i]%=mod1;
        cnt[i]+=mod1;
        cnt[i]%=mod1;
    }
    for(ll i(1);i<=m;++i){
        cout<<cnt[i]<<endl;
    }
     



}
// Do not get stuck on a single approach for long, think of multiple ways
0