#[derive(Debug, Clone)] struct SWAG { front: Vec, back: Vec, unit: T, operator: F, back_agg: T, } impl SWAG where T: std::fmt::Debug + Copy, F: Fn(T, T) -> T, { fn new(unit: T, operator: F) -> Self { Self { front: vec![], back: vec![], unit: unit, operator: operator, back_agg: unit } } fn len(&self) -> usize { self.front.len() + self.back.len() } fn push(&mut self, val: T) { self.back.push(val); self.back_agg = (self.operator)(self.back_agg, val); } fn pop(&mut self) -> Option { if self.front.is_empty() { while let Some(p) = self.back.pop() { let fagg = *self.front.last().unwrap_or(&self.unit); self.front.push((self.operator)(p, fagg)); } self.back_agg = self.unit; } self.front.pop() } fn fold(&self) -> T { (self.operator)(*self.front.last().unwrap_or(&self.unit), self.back_agg) } } fn gcd(a: usize, b: usize) -> usize { fn _gcd(x: usize, y: usize) -> usize { if y == 0 { return x; } gcd(y, x%y) } _gcd(a.max(b), a.min(b)) } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut swag = SWAG::new(0usize, |x, y| gcd(x, y)); let mut ridx = 0usize; let mut result = 0usize; for _ in 0..n { while ridx < n && swag.fold() != 1 { swag.push(a[ridx]); ridx += 1; } result += n - ridx + if swag.fold() == 1 { 1 } else { 0 }; swag.pop(); } println!("{}", result); }