結果
| 問題 |
No.2211 Frequency Table of GCD
|
| コンテスト | |
| ユーザー |
ineedyourlovep
|
| 提出日時 | 2023-02-10 22:04:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 590 ms / 2,000 ms |
| コード長 | 3,440 bytes |
| コンパイル時間 | 2,230 ms |
| コンパイル使用メモリ | 211,256 KB |
| 最終ジャッジ日時 | 2025-02-10 12:47:54 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 1000000007;
const int mod = 998244353;
//MINT
struct mint {
unsigned x;
mint(): x(0) {}
mint(ll x):x((x%mod+mod)%mod) {}
mint operator-() const { return mint(0) - *this;}
mint operator~() const { return mint(1) / *this;}
mint& operator+=(const mint& a) { if((x+=a.x)>=mod) x-=mod; return *this;}
mint& operator-=(const mint& a) { if((x+=mod-a.x)>=mod) x-=mod; return *this;}
mint& operator*=(const mint& a) { x=(unsigned long long)x*a.x%mod; return *this;}
mint& operator/=(const mint& a) { x=(unsigned long long)x*a.pow(mod-2).x%mod; return *this;}
mint operator+(const mint& a) const { return mint(*this) += a;}
mint operator-(const mint& a) const { return mint(*this) -= a;}
mint operator*(const mint& a) const { return mint(*this) *= a;}
mint operator/(const mint& a) const { return mint(*this) /= a;}
mint pow(ll t) const {
if (!t) return 1;
mint res = pow(t>>1);
res *= res;
return (t&1)?res*x:res;
}
bool operator<(const mint& a) const { return x < a.x;}
bool operator==(const mint& a) const { return x == a.x;}
bool operator!=(const mint& a) const { return x != a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream& i, mint& a) { unsigned long long t; i>>t; a=mint(t); return i;}
ostream& operator<<(ostream& o, const mint& a) { return o<<a.x;}
//Eratosthenes
template<typename T>
struct Eratosthenes{
vector<bool> isprime;
vector<T> sieves;
vector<T> minfactor;
vector<T> mobius;
Eratosthenes(T n=0):isprime(n+1, true), minfactor(n+1, -1), mobius(n+1, 1){
isprime[1] = false;
minfactor[1] = 1;
for(T i = 2; i <= n; i++){
if(!isprime[i]) continue;
minfactor[i] = i;
mobius[i] = -1;
for(T j = i*2; j <= n; j += i){
isprime[j] = false;
if(minfactor[j] == -1) minfactor[j] = i;
if((j/i)%i) mobius[j] = -mobius[j];
else mobius[j] = 0;
}
}
for(T i = 2; i <= n; i++) if(isprime[i]) sieves.emplace_back(i);
}
vector<pair<T, T>> factorize(T n){
vector<pair<T, T>> res;
while(n > 1){
int p = minfactor[n];
int exp = 0;
while(minfactor[n] == p){
n /= p;
exp++;
}
res.emplace_back(p, exp);
}
return res;
}
vector<T> divisors(T n){
vector<T> res({1});
auto pf = factorize(n);
for(auto p : pf){
int s = (int)res.size();
for(int i = 0; i < s; i++){
T v = 1;
for(int j = 0; j < p.second; j++){
v *= p.first;
res.push_back(res[i]*v);
}
}
}
return res;
}
};
// POWER_MODver. N^k % MOD
ll mod_pow(ll n, ll k){
ll res = 1;
for(; k > 0; k >>= 1){
if(k&1) res = (res*n)%mod;
n = (n*n)%mod;
}
return res;
}
int main()
{
ll n, m;
cin >> n >> m;
vector<ll> a(n);
rep(i, 0, n) cin >> a[i];
Eratosthenes<ll> d(200005);
map<ll, ll> mp;
rep(i, 0, n) {
auto div = d.divisors(a[i]);
for (auto j : div) {
mp[j]++;
}
}
vector<mint> ans(m+1);
for (ll i = m; i >= 1; i--) {
mint sum = mod_pow(2, mp[i]) - 1;
for (ll j = 2*i; j <= m; j += i) {
sum -= ans[j];
}
ans[i] = sum;
}
rep(i, 1, m+1) cout << ans[i] << "\n";
return 0;
}
ineedyourlovep