Browse Source

046 ok

master
Coin de Gamma 1 year ago
parent
commit
2a5359f15f
  1. 59
      046/main.rs

59
046/main.rs

@ -0,0 +1,59 @@
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;
}
}
}
Loading…
Cancel
Save