use std::collections::{HashMap, HashSet}; //{{{ #[allow(unused_macros)] macro_rules! getl { ( $( $t:ty ),* ) => { { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let s = s.trim_right(); let mut ws = s.split_whitespace(); ($(ws.next().unwrap().parse::<$t>().unwrap()),*) } }; } #[allow(unused_macros)] macro_rules! getl_vec { ( $t:ty ) => {{ let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let s = s.trim_right(); s.split_whitespace() .map(|x| x.parse().unwrap()) .collect::>() }}; } //}}} const MAX: usize = 300_000; fn main() { let n = getl!(usize); let mut a = getl_vec!(usize); let mut c = vec![0usize; MAX]; for a_i in a.iter().copied() { c[a_i] += 1; } let mut sc = vec![0usize]; for c_i in c { let last = sc.last().copied().unwrap(); sc.push(c_i + last); } let sc = sc; let mut map = HashMap::new(); for a_i in a.iter().copied() { let entry = map.entry(a_i).or_insert(0usize); *entry += 1; } let s: usize = a.iter().sum(); let mut ans = 0usize; for (a_i, c_i) in map { let mut now = s * c_i; let mut m = 0; while a_i * m < MAX { // dbg!(now, c_i, m, a_i, &sc[..=10]); if (m + 1) * a_i <= MAX { now -= c_i * m * a_i * (sc[(m + 1) * a_i] - sc[m * a_i]); } else { now -= c_i * m * a_i * (n - sc[m * a_i]); } m += 1; } ans += now; } println!("{}", ans); }