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.
66 lines
1.3 KiB
66 lines
1.3 KiB
use std::collections::HashSet; |
|
|
|
fn er() -> HashSet<u32> { |
|
let mut nums = Vec::new(); |
|
let size = 9999; |
|
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 is_prms(a: u32, b: u32) -> bool { |
|
let aa = a.to_string(); |
|
let bb = b.to_string(); |
|
|
|
let mut hsa = HashSet::new(); |
|
let mut hsb = HashSet::new(); |
|
for c in aa.chars() { |
|
hsa.insert(c); |
|
} |
|
for c in bb.chars() { |
|
hsb.insert(c); |
|
} |
|
|
|
for _ in hsa.difference(&hsb) { |
|
return false; |
|
} |
|
return true; |
|
|
|
} |
|
|
|
fn main() { |
|
let hs = er(); |
|
|
|
for p in hs.iter() { |
|
let p1 = *p; |
|
let p2 = p1 + 3330; |
|
let p3 = p2 + 3330; |
|
if hs.contains(&p1) && hs.contains(&p2) && hs.contains(&p3) { |
|
if is_prms(p1, p2) && is_prms(p2, p3) { |
|
println!("{} {} {}", p1, p2, p3); |
|
} |
|
} |
|
} |
|
|
|
//let pp = is_prms(1487, 3300); |
|
//println!("{}", pp); |
|
|
|
}
|
|
|