From ae22f6ab8c0a3e9d4113f39a767df8338c316f81 Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Wed, 20 Nov 2024 19:06:43 +0000 Subject: [PATCH] solutions: 12 --- highly_divisible_triangular_number.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 highly_divisible_triangular_number.rs diff --git a/highly_divisible_triangular_number.rs b/highly_divisible_triangular_number.rs new file mode 100644 index 0000000..338785a --- /dev/null +++ b/highly_divisible_triangular_number.rs @@ -0,0 +1,26 @@ +pub fn factors(num: u64) -> Vec { + let mut factors: Vec = Vec::new(); + for i in 1..((num as f64).sqrt() as u64 + 1) { + if num % i == 0 { + factors.push(i); + if i != num / i { + factors.push(num / i); + } + } + } + factors +} + +fn main() { + let mut triangular_increment: u64 = 0; + let mut triangular: u64 = 0; + + while factors(triangular).len() <= 500 { + triangular = 0; + for i in 1..=triangular_increment { + triangular += i; + } + triangular_increment += 1; + } + println!("{}", triangular); +}