#include template class SparseTable{ using value_type = typename Semilattice::value_type; std::vector> a; std::vector log_table; public: SparseTable(const std::vector &v){ int n = v.size(); int logn = 0; while((1 << logn) <= n) ++logn; a.assign(n, std::vector(logn)); for(int i = 0; i < n; ++i) a[i][0] = v[i]; for(int j = 1; j < logn; ++j){ for(int i = 0; i < n; ++i){ a[i][j] = Semilattice::op(a[i][j-1], a[std::min(n-1, i+(1<<(j-1)))][j-1]); } } log_table.assign(n+1, 0); for(int i = 2; i < n+1; ++i) log_table[i] = log_table[i>>1] + 1; } inline value_type get(int s, int t) const { // [s,t) int k = log_table[t-s]; return Semilattice::op(a[s][k], a[t-(1<> st) const { value_type ret; bool t = true; for(const auto &p : st){ if(p.first < p.second){ if(t){ ret = get(p.first, p.second); t = false; }else{ ret = Semilattice::op(ret, get(p.first, p.second)); } } } return ret; } }; template struct GcdMonoid{ using value_type = T; constexpr inline static value_type id(){return 0;} constexpr inline static value_type op(const value_type &a, const value_type &b){return std::gcd(a, b);} }; int main(){ int N; while(std::cin >> N){ std::vector A(N); for(int i = 0; i < N; ++i) std::cin >> A[i]; SparseTable> s(A); int64_t ans = 0; for(int l = 0; l < N; ++l){ int lb = l, ub = N+1; while(abs(lb-ub) > 1){ int mid = (lb + ub) / 2; if(s.get(l, mid) == 1){ ub = mid; }else{ lb = mid; } } ans += (N - lb); } std::cout << ans << "\n"; } return 0; }