結果

問題 No.2075 GCD Subsequence
ユーザー HIcoderHIcoder
提出日時 2023-07-12 08:24:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,307 bytes
コンパイル時間 1,192 ms
コンパイル使用メモリ 115,200 KB
実行使用メモリ 43,372 KB
最終ジャッジ日時 2023-10-11 22:27:43
合計ジャッジ時間 36,820 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
18,132 KB
testcase_01 AC 72 ms
6,720 KB
testcase_02 AC 71 ms
7,304 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 TLE -
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 #

/*
余事象
2055
*/
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);

struct Mobius{

    std::vector<int> lists;
    std::vector<bool> isprime;
    int n;
    Mobius(int n_):n(n_){
        lists=std::vector<int>(n+1,1);
        isprime=std::vector<bool>(n+1,true);

        init();
    }

    void init(){

        isprime[0]=isprime[1]=false;
        for(long long i=2;i<=n;i++){
            if(!isprime[i]) continue;//iが素数でない場合


            lists[i]=(-1)*lists[i];

            for(long long j=2*i;j<=n;j+=i){
                isprime[j]=false;

                if( ((j/i)%i)==0 ){
                    //jは (i*i)で割れる
                    lists[j]=0;
                }
                lists[j]*=(-1);
            }
        }
    
    }

    int operator()(int n){
        return lists[n];
    }

    
};

Mobius mobius(1e6+10);

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    map<ll,ll> dp;
    map<ll,ll> g;

    ll tot=0;
    for(int i=0;i<N;i++){
        

        vector<ll> d;
        for(ll x=1;x*x<=A[i];x++){
            if(A[i]%x==0){
                d.push_back(x);
                if(A[i]/x!=x){
                    d.push_back(A[i]/x);
                }
            }
        }


        ll f1=0;

        for(ll v:d){

            //f1+=g[v]*mobius(v);
            if(mobius(v)>0){
                f1+=g[v]%MOD;
                f1%=MOD;
            }else if(mobius(v)<0){
                f1+=(MOD-g[v])%MOD;
                f1%=MOD;
            }
        }

        //ll add=1+tot-f1;
        ll add=0;
        add+=1;
        add+=tot;
        add%=MOD;
        add+=(MOD-f1);
        add%=MOD;


        
        dp[A[i]]+=add;
        dp[A[i]]%=MOD;
        tot+=add;
        tot%=MOD;

        for(ll v:d){
            //A[i]はvで割れる
            g[v]+=dp[A[i]];
            g[v]%=MOD;
        }

    }

    ll ans=0;
    for(auto [key,val]:dp){
        ans+=val;
        ans%=MOD;
    }
    cout<<ans<<endl;

}
0