diff --git a/027/main.rs b/027/main.rs new file mode 100644 index 0000000..007eae1 --- /dev/null +++ b/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); +}