結果
問題 | No.2075 GCD Subsequence |
ユーザー |
![]() |
提出日時 | 2022-09-17 12:10:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,168 bytes |
コンパイル時間 | 1,373 ms |
コンパイル使用メモリ | 108,500 KB |
実行使用メモリ | 9,864 KB |
最終ジャッジ日時 | 2024-12-22 00:40:33 |
合計ジャッジ時間 | 6,633 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 2 WA * 26 |
ソースコード
#include <iostream>#include <vector>#include <map>#include <algorithm>#include <set>#include <stack>#include <queue>#include <cmath>#include <iomanip>#include <numeric>#include <string>#include <bitset>#include <assert.h>// #define _GLIBCXX_DEBUG// #define _LIBCPP_DEBUG 0#define rep(i, n) for (int i = 0; i < (int)(n); ++i)#define revrep(i, n) for(int i = (int)(n -1); i >= 0; --i)#define range(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)#define revrange(i, s, t) for(int i = (int)(t - 1); i >= (int)(s); --i)#define srange(i, s, t, step) for(int i = (int)(s); i < (int)(t); i+=int(step))#define popcnt(x) __builtin_popcountll(x)using namespace std;using ll = long long;using pii = pair<int, int>;using pll = pair<long long, long long>;template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }inline bool inside(int x, int y, int h, int w) { return (x >= 0 && x < h && y >= 0 && y < w); }int dx[] = {0, -1, 0, 1};int dy[] = {-1, 0, 1, 0};const ll mod = 998244353;vector<int> prime_sieve(int n){vector<int> sieve(n+1, 0), prime;for (int i=2; i<n+1; i++){if (sieve[i]==0){sieve[i] = i;prime.emplace_back(i);}for (int p: prime){if (p > sieve[i] || i * p > n) break;sieve[i * p] = p;}}return sieve;}int main() {int n;cin >> n;vector<int> a(n);rep(i, n) cin >> a[i];auto sieve = prime_sieve(1e6);map<int, ll> mp;ll ans = 0;for (auto x: a) {set<int> s;while (sieve[x] != 0) {s.insert(sieve[x]);x /= sieve[x];}ll cnt = 1;for(auto it=s.begin(); it!=s.end(); ++it) {cnt += mp[*it];if (cnt >= mod) cnt -= mod;}for(auto it=s.begin(); it!=s.end(); ++it) {mp[*it] += cnt;if (mp[*it] >= mod) mp[*it] -= mod;}ans += cnt;if (ans >= mod) ans -= mod;}cout << ans << endl;}