use crate::Solution;
use pmath::newtons_method;
problem!(Problem0063, 63, "Powerful Digit Counts");
impl Solution for Problem0063 {
fn solve(&self) -> String {
let mut count = 0;
for y in 1..10_u8 {
let n = newtons_method(
100.0,
1e-10,
|n: f64| 10.0_f64.powf(n - 1.0) - (y as f64).powf(n),
|n: f64| {
10.0_f64.powf(n - 1.0) * 10.0_f64.ln() - (y as f64).powf(n) * (y as f64).ln()
},
)
.unwrap()
.floor() as u64;
count += n;
}
count.to_string()
}
}