結果
問題 |
No.2075 GCD Subsequence
|
ユーザー |
![]() |
提出日時 | 2022-09-16 11:12:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 631 bytes |
コンパイル時間 | 912 ms |
コンパイル使用メモリ | 67,780 KB |
最終ジャッジ日時 | 2025-02-07 05:51:26 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 TLE * 21 |
ソースコード
#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; }