use std::collections::HashSet; fn main() { let mut ps = HashSet::new(); let mut hs = HashSet::new(); let N = 500000u64; for n in 1..N { hs.insert(n*(2*n-1)); } for n in 1..N { ps.insert(n*(3*n -1)/2 ); } for n in 286u64..N { let tn = n * (n+1)/2; if !hs.contains(&tn) { continue; } if !ps.contains(&tn) { continue; } println!("{}", tn); break; } }