結果

問題 No.2075 GCD Subsequence
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-08-06 07:29:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 671 ms / 4,000 ms
コード長 1,813 bytes
コンパイル時間 6,741 ms
コンパイル使用メモリ 336,620 KB
実行使用メモリ 22,852 KB
最終ジャッジ日時 2024-04-24 03:36:09
合計ジャッジ時間 19,546 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
11,648 KB
testcase_01 AC 19 ms
11,776 KB
testcase_02 AC 19 ms
11,776 KB
testcase_03 AC 19 ms
11,776 KB
testcase_04 AC 18 ms
11,648 KB
testcase_05 AC 20 ms
11,648 KB
testcase_06 AC 19 ms
11,776 KB
testcase_07 AC 19 ms
11,700 KB
testcase_08 AC 403 ms
19,744 KB
testcase_09 AC 669 ms
22,736 KB
testcase_10 AC 445 ms
20,028 KB
testcase_11 AC 575 ms
21,592 KB
testcase_12 AC 510 ms
20,740 KB
testcase_13 AC 360 ms
18,920 KB
testcase_14 AC 567 ms
21,712 KB
testcase_15 AC 365 ms
19,332 KB
testcase_16 AC 406 ms
19,752 KB
testcase_17 AC 664 ms
22,852 KB
testcase_18 AC 614 ms
13,540 KB
testcase_19 AC 671 ms
13,416 KB
testcase_20 AC 620 ms
13,536 KB
testcase_21 AC 618 ms
13,412 KB
testcase_22 AC 616 ms
13,416 KB
testcase_23 AC 658 ms
13,412 KB
testcase_24 AC 639 ms
13,668 KB
testcase_25 AC 658 ms
13,540 KB
testcase_26 AC 640 ms
13,416 KB
testcase_27 AC 659 ms
13,416 KB
testcase_28 AC 476 ms
12,544 KB
testcase_29 AC 20 ms
11,760 KB
testcase_30 AC 19 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
struct divs{
  int n;
  vector<int> f, primes;
  divs(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<pair<int,int>> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<pair<int,int>> res(1, pair<int,int>(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vc<int>mev(int x){
  	auto fl=factor(x);
  	vc<int>res;
  	for(auto [a,z]:fl){
  		for(int i=res.size()-1;i>=0;i--)res.pb(res[i]*a);
  		res.pb(a);
  	}
  	return res;
  }
};
int main(){
	int n;cin>>n; int m=1e6;
	vc<int>v(n); rep(i,n)cin>>v[i];
	map<int,mint>mp;
	vc<int>mv(m+1,-1);
	divs d(m);
	for(ll au:d.primes)for(ll i=au*au;i<=m;i+=au*au)mv[i]=0;
	for(auto au:d.primes)for(int i=au;i<=m;i+=au)mv[i]*=-1;
	mint ans=0;
	rep(i,n){
		int a=v[i];
		mint now=1;
		for(auto au:d.mev(a))now+=mv[au]*mp[au];
		for(auto au:d.mev(a))mp[au]+=now;
		ans+=now;
	}
	cout<<ans.val();
}
	
	
0