Browse Source

027 ok

master
Coin de Gamma 1 year ago
parent
commit
14a1149def
  1. 46
      027/main.rs

46
027/main.rs

@ -0,0 +1,46 @@
// TODO: iterate over Sieve of Eratosthenes
fn is_prime(k: i32) -> bool {
if k < 0 {
return false;
}
for i in 2..k {
if k % i == 0 {
return false;
}
}
return true;
}
fn get_primes(a: i32, b: i32) -> i32 {
let mut n = 0;
loop {
if is_prime(n*n + a * n + b) {
n += 1;
} else {
break;
}
}
return n;
}
fn main() {
println!("hello world");
//let ip = is_prime(8);
let mut max_a = 0;
let mut max_b = 0;
let mut max_l = 0;
for a in -1000..1000 {
for b in -1000..1000 {
let l = get_primes(a, b);
if l > max_l {
max_a = a;
max_b = b;
max_l = l;
println!(">> {}", l);
}
}
}
println!("{} {} {}", max_a, max_b, max_l);
println!("{}", max_a * max_b);
}
Loading…
Cancel
Save