結果

問題 No.2075 GCD Subsequence
ユーザー HIcoderHIcoder
提出日時 2023-07-12 08:30:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,488 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 107,856 KB
実行使用メモリ 24,384 KB
最終ジャッジ日時 2023-10-11 22:33:37
合計ジャッジ時間 44,489 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
22,660 KB
testcase_01 AC 82 ms
22,572 KB
testcase_02 AC 81 ms
22,548 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 AC 2,489 ms
24,180 KB
testcase_29 WA -
testcase_30 AC 81 ms
22,504 KB
権限があれば一括ダウンロードができます

ソースコード

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;

    vector<ll> dp(1000000+10,0);
    vector<ll> g(1000000+10,0);

    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 x:d){

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

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


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

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

    }

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

}
0