1
0
This commit is contained in:
2026-02-04 11:15:03 +08:00
commit 8b20a5dd21
125 changed files with 4177 additions and 0 deletions

6
problems/p12/Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "p12"
version = "0.1.0"
edition = "2024"
[dependencies]

42
problems/p12/src/main.rs Normal file
View File

@@ -0,0 +1,42 @@
struct TriNum {
current: usize,
sum: usize,
}
impl TriNum {
fn new() -> Self {
Self { current: 0, sum: 0 }
}
}
impl Iterator for TriNum {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> {
self.current += 1;
self.sum += self.current;
Some(self.sum)
}
}
fn factor_count(input: usize) -> usize {
let max = (input as f32).sqrt() as usize;
let mut count = 0;
for i in 1..=max {
if input % i == 0 {
count += 2;
}
}
count
}
fn main() {
let tri_num = TriNum::new();
for i in tri_num {
let count = factor_count(i);
if count > 500 {
println!("i: {i}");
break;
}
}
}