結果
| 問題 | 
                            No.1036 Make One With GCD 2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ngtkana
                         | 
                    
| 提出日時 | 2020-04-24 21:42:09 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 282 ms / 2,000 ms | 
| コード長 | 915 bytes | 
| コンパイル時間 | 2,183 ms | 
| コンパイル使用メモリ | 195,416 KB | 
| 最終ジャッジ日時 | 2025-01-09 23:23:31 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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);
    for(lint&x:a)std::cin>>x;
    lint ans=n*(n+1)/2;
    for(lint l=0,c=0,r=0,g=0;l<n;l++){
        lint h=c==l?0:a.at(l);
        for(;r<n;g=std::gcd(g,a.at(r)),r++){
            lint nhg=std::gcd(std::gcd(h,g),a.at(r));
            if(nhg==1)break;
        }
        ans-=r-l;
        if(l==r){
            assert(g==0);
            c++;
            r++;
        }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=0;
        }
    }
    std::cout<<ans<<'\n';
}
            
            
            
        
            
ngtkana