結果
問題 |
No.1036 Make One With GCD 2
|
ユーザー |
![]() |
提出日時 | 2020-04-24 22:47:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 271 ms / 2,000 ms |
コード長 | 936 bytes |
コンパイル時間 | 2,291 ms |
コンパイル使用メモリ | 196,108 KB |
最終ジャッジ日時 | 2025-01-10 00:18:13 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
ソースコード
#include<bits/stdc++.h> #define ALL(v) std::begin(v),std::end(v) using lint=long long; using ld=long double; template<class T>using numr=std::numeric_limits<T>; int main(){ std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed);std::cout.precision(15); lint n;std::cin>>n; std::vector<lint>a(n),g(n+1); for(lint&x:a)std::cin>>x; lint ans=n*(n+1)/2; for(lint l=0,c=0,r=0;l<n;l++){ lint h=c==l?0:a.at(l); for(;r<n;r++){ g.at(r+1)=std::gcd(g.at(r),a.at(r)); lint hg=std::gcd(h,g.at(r+1)); if(hg==1)break; } ans-=r-l; if(l==r){ c++; r++; g.at(r)=0; }else if(l==c){ for(c=r-2;c>=l;c--){ a.at(c)=std::gcd(a.at(c),a.at(c+1)); } c=r; g.at(r)=0; } } std::cout<<ans<<'\n'; }