From 14a1149def08965531246f3c2353fa03a8a028ac Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Sat, 4 Nov 2023 07:14:49 +0000 Subject: [PATCH] 027 ok --- 027/main.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 027/main.rs 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); +}