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.
47 lines
915 B
47 lines
915 B
1 year ago
|
// 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);
|
||
|
}
|