#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; template struct DisjointSparseTable { using Fn = function; DisjointSparseTable(const vector &a, Fn fn) : fn(fn) { int n = a.size(), table_h = 1; while ((1 << table_h) < n) ++table_h; lg.assign(1 << table_h, 0); FOR(i, 2, 1 << table_h) lg[i] = lg[i >> 1] + 1; dat.assign(table_h, vector(n)); REP(j, n) dat[0][j] = a[j]; FOR(i, 1, table_h) { int shift = 1 << i; for (int left = 0; left < n; left += shift << 1) { int mid = min(left + shift, n); dat[i][mid - 1] = a[mid - 1]; for (int j = mid - 2; j >= left; --j) dat[i][j] = fn(a[j], dat[i][j + 1]); if (n <= mid) break; int right = min(mid + shift, n); dat[i][mid] = a[mid]; for (int j = mid + 1; j < right; ++j) dat[i][j] = fn(dat[i][j - 1], a[j]); } } } Semigroup query(int left, int right) { assert(left < right); if (left == --right) return dat[0][left]; int h = lg[left ^ right]; return fn(dat[h][left], dat[h][right]); } private: Fn fn; vector lg; vector> dat; }; int main() { int n; cin >> n; vector a(n); REP(i, n) cin >> a[i]; DisjointSparseTable dst(a, [](ll a, ll b) { return gcd(a, b); }); ll ans = 0; REP(i, n) { if (a[i] == 1) { ans += n - i; continue; } int lb = i, ub = n; while (ub - lb > 1) { int mid = (lb + ub) >> 1; (dst.query(i, mid + 1) > 1 ? lb : ub) = mid; } ans += n - ub; } cout << ans << '\n'; return 0; }