// ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- fn run() { input! { n: usize, m: usize, a: [usize; m], } let w = n; let mut f = (0..=w).collect::>(); for i in 2..=w { if i * i > w { break; } if i == f[i] { for j in i..=(w / i) { f[j * i] = i; } } } let mut memo = vec![0; n + 1]; let mut ans = 0; for a in a { if memo[a] == 0 { let mut d = vec![1]; let mut b = a; while b > 1 { let p = f[b]; let mut c = 0; while b % p == 0 { b /= p; c += 1; } let len = d.len(); let mut mul = 1; for _ in 0..c { mul *= p; for i in 0..len { let v = d[i] * mul; d.push(v); } } } d.sort(); let mut sum = vec![0; d.len()]; for (s, d) in sum.iter_mut().zip(d.iter()) { *s = a / *d; } let mut b = a; while b > 1 { let p = f[b]; while b % p == 0 { b /= p; } let mut j = 0; for i in 0..d.len() { if d[i] * p > a { break; } if a / d[i] % p != 0 { continue; } while d[i] * p != d[j] { j += 1; } sum[i] -= sum[j]; } } for (d, s) in d.iter().zip(sum.iter()) { memo[a] += ((a - 1) % *d) * *s; } } ans += memo[a]; } println!("{}", ans); } fn main() { run(); }