/* ---------- STL Libraries ---------- */ // IO library #include #include #include #include #include // algorithm library #include #include #include #include #include #include // container library #include #include #include #include #include #include #include #include #include #include #include // type #include #include /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll template using MaxHeap = priority_queue; template using MinHeap = priority_queue, greater>; #define P pair /* ---------- Constants */ const double PI = 3.141592653589793238462643383279; const ll MOD = 1e9 + 7; const int INF = 1LL << 55; /* ---------- Functions */ template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } /* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */ int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a%b); } template class SegTree { int N; vector data; T ide; // Identity element (Initial value) function operation; // Function for range query function updater; // Function for point update T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return ide; if (a <= l && r <= b) { return data[k]; } else { T left = _query(a, b, 2 * k + 1, l, (l + r) / 2); T right = _query(a, b, 2 * k + 2, (l + r) / 2, r); return operation(left, right); } } public: // int n: Size of array // T ide: Identity element // function operation: Function to merge elements // function updater: (old data[i], some value x) -> new data[i] SegTree(size_t n, T ide, function operation, function updater) : ide(ide), operation(operation), updater(updater) { N = 1; while (N < n) N *= 2; data.resize(2 * N - 1, ide); } void update(int i, T x) { i += N - 1; data[i] = updater(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, N); } T operator[](int i) { return data[i + N - 1]; } }; signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) cin >> A[i]; ll ide = INF; auto operation = [](int left, int right) -> int { if (left==INF) return right; if (right == INF) return left; return gcd(left, right); }; auto updater = [](int old, int x) -> int {return x;}; auto seg = new SegTree(N, ide, operation, updater); for (int i = 0; i < N; i++) seg->update(i, A[i]); int ret= 0; // [left, right] int right = 0; for (int left = 0; left < N; left++) { while (right < N && seg->query(left, right+1) != 1) right++; if (right == N) break; ret += N-right; } cout << ret << endl; return 0; }