use crate::Solution;
use pmath::factors::divisors;
problem!(Problem0012, 12, "Highly Divisible Triangular Number");
impl Solution for Problem0012 {
fn solve(&self) -> String {
let mut n: u32 = 5;
let mut d_t1 = divisors(n).count() as i32;
let mut d_t2 = divisors(n.div_ceil(2)).count() as i32;
while d_t1 * d_t2 <= 500 {
n += 1;
d_t1 = d_t2;
if n % 2 == 0 {
d_t2 = divisors(n + 1).count() as i32;
} else {
d_t2 = divisors(n.div_ceil(2)).count() as i32;
}
}
(n * (n + 1) / 2).to_string()
}
}