結果

問題 No.2075 GCD Subsequence
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2022-09-16 11:12:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 631 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 69,244 KB
実行使用メモリ 11,728 KB
最終ジャッジ日時 2023-08-23 06:10:45
合計ジャッジ時間 7,419 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,560 KB
testcase_01 AC 5 ms
11,512 KB
testcase_02 AC 5 ms
11,500 KB
testcase_03 AC 5 ms
11,512 KB
testcase_04 AC 5 ms
11,524 KB
testcase_05 AC 5 ms
11,728 KB
testcase_06 AC 5 ms
11,544 KB
testcase_07 AC 5 ms
11,520 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cassert>
#include<iostream>
using namespace std;
typedef long long lint;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const lint mod=998244353;
#define N 1000001

void add(lint&a,lint b){
  a+=b;
  if(a>=mod)a-=mod;
}

int v[N];
lint dp[N];

int gcd(int a,int b){
  while(b){
    int r=a%b;
    a=b,b=r;
  }
  return a;
}

// TLE 解法。
int main(){
  int n;cin>>n;
  for(int i=2;i<N;i++)dp[i]=1;
  lint ans=0;
  rep(i,n){
    int a;cin>>a;
    v[i]=a;
    if(a==1){
      add(ans,1);
      continue;
    }
    dp[i]=1;
    rep(j,i)
      if(gcd(v[j],a)!=1)add(dp[i],dp[j]);
    add(ans,dp[i]);
  }
  cout<<ans<<endl;
}
0