結果

問題 No.2075 GCD Subsequence
ユーザー HIcoderHIcoder
提出日時 2023-07-12 08:33:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,545 bytes
コンパイル時間 1,305 ms
コンパイル使用メモリ 115,388 KB
実行使用メモリ 119,740 KB
最終ジャッジ日時 2023-10-11 22:37:15
合計ジャッジ時間 34,339 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
18,092 KB
testcase_01 AC 72 ms
6,936 KB
testcase_02 AC 70 ms
6,764 KB
testcase_03 AC 71 ms
7,300 KB
testcase_04 AC 71 ms
7,232 KB
testcase_05 AC 74 ms
6,700 KB
testcase_06 AC 72 ms
6,824 KB
testcase_07 AC 74 ms
6,752 KB
testcase_08 AC 2,080 ms
31,976 KB
testcase_09 AC 3,470 ms
43,024 KB
testcase_10 AC 2,178 ms
33,124 KB
testcase_11 AC 2,908 ms
38,984 KB
testcase_12 AC 2,486 ms
35,780 KB
testcase_13 AC 1,810 ms
29,740 KB
testcase_14 AC 2,824 ms
38,612 KB
testcase_15 AC 1,904 ms
30,900 KB
testcase_16 AC 2,068 ms
32,240 KB
testcase_17 AC 3,382 ms
42,548 KB
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 #

/*


余事象を用いる
yukicoder 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]+=add;//同時にgも更新.
            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