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.
31 lines
628 B
31 lines
628 B
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); |
|
|
|
}
|
|
|