#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/DataStructure/sliding_window_aggregation.hpp" #include template struct SlidingWindowAggregation { using T = typename M::T; std::stack> front, back; explicit SlidingWindowAggregation() = default; void push(const T& x) { T acc = M::op(back.empty() ? M::id : back.top().second, x); back.emplace(x, acc); } void pop() { if (front.empty()) { T acc = M::id; while (!back.empty()) { acc = M::op(back.top().first, acc); front.emplace(back.top().first, acc); back.pop(); } } front.pop(); } T fold() { return M::op((front.empty() ? M::id : front.top().second), (back.empty() ? M::id : back.top().second)); } }; #line 2 "main.cpp" #include #include #include using namespace std; using lint = long long; struct GCD { using T = lint; static T op(T a, T b) { return gcd(a, b); } static const T id = 0; }; void solve() { int n; cin >> n; lint ans = 0; SlidingWindowAggregation swa; int r = 0; for (int l = 0; l < n; ++l) { while (swa.fold() != 1 && r < n) { lint x; cin >> x; swa.push(x); ++r; } if (swa.fold() == 1) ans += n - r + 1; swa.pop(); } cout << ans << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }