Language: C++

#include<iostream>
#include<vector>

using std::cin;
using std::cout;
using std::endl;

template<class T,class F>
struct segment_tree{
  std::vector<T> data;
  int n;
  F f;
  T identity;
  segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){
    n = 1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
  }
  segment_tree(std::vector<T> const& v,T ide,F _f):f(_f),identity(ide){
    build(v);
  }
  void build(std::vector<T> const& v){
    int sz = v.size();
    n = 1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
    for(int i=0;i<sz;++i)data[i+n]=v[i];
    for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  void set(int i,T x){
    i += n;
    data[i] = x;
    while(i,i>>=1)data[i] = f(data[i<<1|0],data[i<<1|1]);
  }
  T query(int l,int r)const{
    l += n, r += n;
    T x = identity;
    while(l<r){
      if(l&1)x = f(x,data[l++]);
      if(r&1)x = f(x,data[--r]);
      l>>=1, r>>=1;
    }
    return x;
  }
  T operator[](int i)const{
    return data[i+n];
  }
};
template<class T,class F>
auto make_segtree(int n,T ide,F f){
  return segment_tree<T,F>(n,ide,f);
}
template<class T,class F>
auto make_segtree(std::vector<T>const& v,T ide,F f){
  return segment_tree<T,F>(v,ide,f);
}

signed main(){
  int n;
  cin>>n;
  std::vector<int64_t> a(n);
  for(auto& ai:a)cin>>ai;
  auto gcd = [](auto a,auto b){
    while(1){
      a %= b;
      std::swap(a,b);
    }
  };
  auto seg = make_segtree<int64_t>(a,0,gcd);
  int64_t ans = 1;
  for(int i=0;i<n;++i){
    seg.set(i,0);
    ans = std::max(ans,seg.query(0,n));
    seg.set(i,a[i]);
  }
  cout<<(ans)<<endl;
}

Compiler output:
a.cc: In instantiation of 'void segment_tree<T, F>::set(int, T) [with T = long int; F = main()::<lambda(auto:1, auto:2)>]':
a.cc:71:12:   required from here
   71 |     seg.set(i,0);
      |     ~~~~~~~^~~~~
a.cc:32:30: error: void value not ignored as it ought to be
   32 |     while(i,i>>=1)data[i] = f(data[i<<1|0],data[i<<1|1]);
      |                             ~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In instantiation of 'T segment_tree<T, F>::query(int, int) const [with T = long int; F = main()::<lambda(auto:1, auto:2)>]':
a.cc:72:33:   required from here
   72 |     ans = std::max(ans,seg.query(0,n));
      |                        ~~~~~~~~~^~~~~
a.cc:38:19: error: void value not ignored as it ought to be
   38 |       if(l&1)x = f(x,data[l++]);
      |                  ~^~~~~~~~~~~~~
a.cc:39:19: error: void value not ignored as it ought to be
   39 |       if(r&1)x = f(x,data[--r]);
      |                  ~^~~~~~~~~~~~~
a.cc: In instantiation of 'void segment_tree<T, F>::build(const std::vector<T>&) [with T = long int; F = main()::<lambda(auto:1, auto:2)>]':
a.cc:20:5:   required from 'segment_tree<T, F>::segment_tree(const std::vector<T>&, T, F) [with T = long int; F = main()::<lambda(auto:1, auto:2)>]'
   20 |     build(v);
      |     ^~~~~
a.cc:54:10:   required from 'auto make_segtree(const std::vector<T>&, T, F) [with T = long int; F = main()::<lambda(auto:1, auto:2)>]'
   54 |   return segment_tree<T,F>(v,ide,f);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:68:35:   required from here
   68 |   auto seg = make_segtree<int64_t>(a,0,gcd);
      |              ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
a.cc:27:36: error: void value not ignored as it ought to be
   27 |     for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);
      |                                   ~^~~~~~~~~~~~~~~~~~~~~~~~~~~