From e12b8a76ce7ce7a2b6453068141a36f89c351b0c Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Sun, 17 Dec 2023 12:53:19 +0000 Subject: [PATCH] 044 ok --- 044/main.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 044/main.rs diff --git a/044/main.rs b/044/main.rs new file mode 100644 index 0000000..715dde4 --- /dev/null +++ b/044/main.rs @@ -0,0 +1,31 @@ +use std::collections::HashSet; + +fn main() { + let mut hs = HashSet::new(); + for n in 1..10000 { + let pn = n * ( 3*n -1 ) / 2; + hs.insert(pn); + } + let mut D = 10000000; + for p in hs.iter() { + for q in hs.iter() { + if q <= p { + continue; + } + + let s = *p + *q; + if !hs.contains(&s) { + continue; + } + let d = *q - *p; + if !hs.contains(&d) { + continue; + } + if d < D { + D = d; + } + } + } + println!("{}", D); + +}