Skip to content

Instantly share code, notes, and snippets.

@tokugh
Created June 23, 2021 04:42
Show Gist options
  • Save tokugh/66ef3c27d280a4a45cb0022aed1568d1 to your computer and use it in GitHub Desktop.
Save tokugh/66ef3c27d280a4a45cb0022aed1568d1 to your computer and use it in GitHub Desktop.
use itertools::Itertools;
fn main() {
proconio::input! { n: i64, b: i64, };
let mut log10b = 0;
while 10i64.pow(log10b) <= b { log10b += 1; }
let log10b = log10b as usize;
let digits_iter = (0..=9).combinations_with_replacement(log10b);
let mut ans = 0;
for digits in digits_iter {
let f: i64 = digits.iter().product();
let mut m = b + f;
if m > n { continue; }
let mut m_digits = vec![];
for _ in 0..log10b {
m_digits.push(m % 10);
m /= 10;
}
m_digits.sort();
if m_digits == digits { ans += 1; eprintln!("{:?}", digits); }
}
println!("{}", ans);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment