結果

問題 No.2075 GCD Subsequence
ユーザー SSRSSSRS
提出日時 2022-09-16 21:51:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,066 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 173,780 KB
実行使用メモリ 95,588 KB
最終ジャッジ日時 2023-08-23 15:00:15
合計ジャッジ時間 47,270 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,316 ms
94,480 KB
testcase_01 AC 1,313 ms
94,568 KB
testcase_02 AC 1,303 ms
94,484 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1,244 ms
94,492 KB
testcase_30 AC 1,213 ms
94,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000000;
const long long MOD = 998244353;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<bool> prime(MAX + 1, true);
  vector<int> mobius(MAX + 1, 1);
  for (int i = 2; i <= MAX; i++){
    if (prime[i]){
      for (int j = 1; j * i <= MAX; j++){
        if (j > 1){
          prime[i * j] = false;
        }
        mobius[i * j] *= -1;
        if (j % i == 0){
          mobius[i * j] = 0;
        }
      }
    }
  }
  vector<vector<int>> F(MAX + 1);
  for (int i = 2; i <= MAX; i++){
    if (mobius[i] != 0){
      for (int j = i; j <= MAX; j += i){
        F[j].push_back(i);
      }
    }
  }
  vector<long long> dp(MAX + 1, 0);
  long long ans = 0;
  for (int i = 0; i < N; i++){
    long long sum = 1;
    for (int j : F[A[i]]){
      sum += dp[j] * (-mobius[j]) + MOD;
    }
    sum %= MOD;
    ans += sum;
    for (int j : F[A[i]]){
      dp[j] += sum * (-mobius[j]) + MOD;
      dp[j] %= MOD;
    }
  }
  cout << ans << endl;
}
0