You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2 KiB

use std::collections::HashSet;
type HS = HashSet<u32>;
fn er() -> HS {
let mut nums = Vec::new();
let size = 1_000_000;
for n in 0..size+1 { nums.push(true); }
let mut p = 1;
loop {
let mut found = false;
for i in p+1..size {
if nums[i] {
found = true;
p = i;
break;
}
}
if !found { break; }
for i in (2 * p .. size).step_by(p) {
nums[i] = false;
}
}
let mut res = HashSet::new();
for i in 2..size {
if nums[i] { res.insert(i as u32); }
}
return res;
}
fn sqs() -> HS {
let mut res = HS::new();
for n in 1..1_000_0 {
res.insert(n*n);
}
return res;
}
fn test(n: u32, ps: &HS, sq: &HS) -> bool {
for k in 7..n {
if !ps.contains(&k) { continue }
let s = (n - k) / 2;
if !sq.contains(&s) { continue }
return true;
}
return false;
}
fn main() {
let ps = er();
let sq = sqs();
for k in (9..100000).step_by(2) {
if ps.contains(&k) { continue; }
if !test(k, &ps, &sq) {
println!("{}", k);
break;
}
}
}