結果

問題 No.2075 GCD Subsequence
コンテスト
ユーザー Nzt3
提出日時 2022-09-24 03:03:45
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,200 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,070 ms
コンパイル使用メモリ 200,196 KB
最終ジャッジ日時 2026-06-27 17:24:12
合計ジャッジ時間 2,769 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:76,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:62,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bit: In instantiation of 'constexpr int std::__popcount(_Tp) [with _Tp = int]':
main.cpp:35:20:   required from here
   35 |       if(__popcount(j)%2==1)s=min(s+cnt[k],s+cnt[k]-mod);
      |          ~~~~~~~~~~^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bit:308:34: error: argument 1 in call to function '__builtin_popcountg' has signed type
  308 |       return __builtin_popcountg(__x);
      |                                  ^~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

const int mod=998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector<int>A(N);
  for(int &i:A)cin>>i;
  vector<unsigned>cnt(1000001);
  unsigned ans=0;
  for(int i=0;i<N;i++){
    if(A[i]==1){
      ++ans;
      continue;
    }
    int p=A[i];
    vector<int>d;
    for(int j=2;j*j<=p;j++){
      if(p%j==0){
        d.push_back(j);
        while(p%j==0)p/=j;
      }
    }
    if(p!=1)d.push_back(p);
    int s=1;
    for(int j=1;j<1<<d.size();j++){
      int k=1;
      for(int l=0;l<d.size();l++){
        if(j>>l&1)k*=d[l];
      }
      if(__popcount(j)%2==1)s=min(s+cnt[k],s+cnt[k]-mod);
      else s=min(s+mod-cnt[k],s-cnt[k]);
    }
    for(int j=1;j<1<<d.size();j++){
      int k=1;
      for(int l=0;l<d.size();l++){
        if(j>>l&1)k*=d[l];
      }
      cnt[k]=min(s+cnt[k],s+cnt[k]-mod);
    }
  }
  vector<int>hurui(1000001);
  for(int i=2;i<=1000000;i++){
    if(hurui[i]!=0)continue;
    for(int j=i;j<=1000000;j+=i)++hurui[j];
  }
  for(int i=2;i<=1000000;i++){
    if(hurui[i]%2)ans=min(ans+cnt[i],ans+cnt[i]-mod);
    else ans=min(ans+mod-cnt[i],ans-cnt[i]);
  }
  cout<<ans<<'\n';
}
0