結果
問題 | No.2211 Frequency Table of GCD |
ユーザー |
![]() |
提出日時 | 2023-04-23 16:22:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 1,791 bytes |
コンパイル時間 | 466 ms |
コンパイル使用メモリ | 42,496 KB |
実行使用メモリ | 5,504 KB |
最終ジャッジ日時 | 2024-11-07 23:23:31 |
合計ジャッジ時間 | 4,365 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
/* -*- coding: utf-8 -*-** 2211.cc: No.2211 Frequency Table of GCD - yukicoder*/#include<cstdio>#include<algorithm>using namespace std;/* constant */const int MAX_N = 200000;const int MAX_M = 200000;const int MOD = 998244353;/* typedef */template<const int MOD>struct MI {int v;MI(): v() {}MI(int _v): v(_v % MOD) {}MI(long long _v): v(_v % MOD) {}MI operator+(const MI m) const { return MI(v + m.v); }MI operator-(const MI m) const { return MI(v + MOD - m.v); }MI operator*(const MI m) const { return MI((long long)v * m.v); }MI &operator+=(const MI m) { return (*this = *this + m); }MI &operator-=(const MI m) { return (*this = *this - m); }MI &operator*=(const MI m) { return (*this = *this * m); }bool operator==(const MI m) const { return v == m.v; }bool operator!=(const MI m) const { return v != m.v; }MI pow(int n) const { // a^n % MODMI pm = 1, a = *this;while (n > 0) {if (n & 1) pm *= a;a *= a;n >>= 1;}return pm;}MI inv() const { return pow(MOD - 2); }MI operator/(const MI m) const { return *this * m.inv(); }MI &operator/=(const MI m) { return (*this = *this / m); }};typedef MI<MOD> mi;/* global variables */int cs[MAX_M + 1], gcs[MAX_M + 1];mi gs[MAX_M + 1];/* subroutines *//* main */int main() {int n, m;scanf("%d%d", &n, &m);for (int i = 0; i < n; i++) {int ai;scanf("%d", &ai);cs[ai]++;}for (int i = 1; i <= m; i++)for (int j = i; j <= m; j += i) gcs[i] += cs[j];for (int i = 1; i <= m; i++)gs[i] = mi(2).pow(gcs[i]) - 1;for (int i = m; i >= 1; i--)for (int j = i * 2; j <= m; j += i)gs[i] -= gs[j];for (int i = 1; i <= m; i++) printf("%d\n", gs[i].v);return 0;}