use std::io::{stdin, Read}; fn main() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut tok = buf.split_whitespace(); let mut get = || tok.next().unwrap(); macro_rules! get { ($t:ty) => (get().parse::<$t>().unwrap()); () => (get!(usize)); } let n = get!(); let mut ans = 0; let mut vs = vec![]; let mut g = vec![vec![false; n + 1]; n + 1]; for i in 2..n+1 { for j in i+1..n+1 { let r = gcd(i, j) != 1; g[i][j] = r; g[j][i] = r; } } solve(&mut ans, &mut vs, 0, n, false, &g); println!("{}", ans); } fn solve(ans: &mut usize, vs: &mut Vec, sum: usize, i: usize, even: bool, g: &Vec>) { if i < 2 { if sum > *ans { *ans = sum; } return; } let mut ok = true; for &v in vs.iter() { if g[i][v] { ok = false; break; } } if ok { vs.push(i); if i % 2 == 0 { solve(ans, vs, sum + i, i - 1, true, g); } else if even { solve(ans, vs, sum + i, i - 2, even, g); } else { solve(ans, vs, sum + i, i - 1, even, g); } vs.pop(); } if even { solve(ans, vs, sum, i - 2, even, g); } else { solve(ans, vs, sum, i - 1, even, g); } } // doc.rust-lang.org/std/ops/trait.Div.html fn gcd(x: usize, y: usize) -> usize { let mut x = x; let mut y = y; while y != 0 { let t = y; y = x % y; x = t; } x }