use std::io::*; mod sparse_table { pub struct SparseTable { table: Vec>, func: F, } impl T> SparseTable { pub fn new(a: &Vec, id: T, f: F) -> SparseTable { let n = a.len(); let max_log = (32 - (n as u32).leading_zeros()) as usize; let mut table = vec![vec![id; n]; max_log]; table[0] = a.clone(); for j in 1..max_log { for i in 0..n - (1 << j) + 1 { table[j][i] = f(table[j - 1][i], table[j - 1][i + (1 << (j - 1))]); } } SparseTable { table: table, func: f, } } pub fn get(&self, from: usize, to: usize) -> T { assert!(from <= to && to <= self.table[0].len() - 1); let lg = (32 - ((to - from + 1) as u32).leading_zeros() - 1) as usize; (self.func)(self.table[lg][from], self.table[lg][to + 1 - (1 << lg)]) } } } fn gcd(a: u64, b: u64) -> u64 { if b == 0 { return a; } gcd(b, a % b) } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let st = sparse_table::SparseTable::new(&a, 1, gcd); let mut ans = a.iter().filter(|&e| *e == 1).count(); for i in 0..n { if st.get(i, n - 1) != 1 { continue; } let mut ng = i; let mut ok = n; while ok - ng > 1 { let mid = (ok + ng) >> 1; if st.get(i, mid) == 1 { ok = mid } else { ng = mid } } ans += n - ok; } println!("{}", ans); }