Browse Source

058 with bugs

master
Coin de Gamma 10 months ago
parent
commit
68c4dd93e8
  1. 30
      058/main.rs

30
058/main.rs

@ -1,9 +1,11 @@
use std::collections::HashSet; use std::collections::HashSet;
const UP: usize = 100;
// from../ 027/main.rs // from../ 027/main.rs
fn er() -> HashSet<u32> { fn er() -> HashSet<usize> {
let mut nums = Vec::new(); let mut nums = Vec::new();
let size = 600_000_000; let size = UP;
for _n in 0..size+1 { nums.push(true); } for _n in 0..size+1 { nums.push(true); }
let mut p = 1; let mut p = 1;
loop { loop {
@ -22,7 +24,7 @@ fn er() -> HashSet<u32> {
} }
let mut res = HashSet::new(); let mut res = HashSet::new();
for i in 2..size { for i in 2..size {
if nums[i] { res.insert(i as u32); } if nums[i] { res.insert(i); }
} }
return res; return res;
} }
@ -43,7 +45,7 @@ impl Steps {
}; };
} }
fn next(&mut self, n: u32) -> Option<u32> { fn next(&mut self, n: usize) -> Option<usize> {
if self.k > self.l { if self.k > self.l {
self.k = 1; self.k = 1;
self.s += 1; self.s += 1;
@ -72,14 +74,15 @@ impl Steps {
fn main() { fn main() {
let mut st = Steps::new(); let mut st = Steps::new();
println!("er begin");
let ps = er(); let ps = er();
println!("er"); println!("er end");
return; //return;
let mut sq = 1; let mut sq = 1;
let mut corner_count = 0; let mut corner_count = 1;
let mut p_count = 0; let mut p_count = 1;
for n in 1..900_000_000 { for n in 1..UP {
if n > sq * sq { if n >= sq * sq {
sq += 1; sq += 1;
} }
match st.next(n) { match st.next(n) {
@ -89,10 +92,9 @@ fn main() {
if is_prime { if is_prime {
p_count += 1; p_count += 1;
} }
println!("{} {} {} {}", n, sq, corner_count, p_count);
let ratio = 100.0 * (p_count as f64) /(corner_count as f64); if ((p_count as f64) * 100f64 as f64) / (corner_count as f64) < 60f64 {
println!("{}.{} \t({})\t[{}]", k, is_prime, sq, ratio); println!("!!{}", sq);
if ratio < 10.0 {
break; break;
} }
}, },

Loading…
Cancel
Save