https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_by
を判定すればよいですが、でなければが大きいならを掛けていけばそのうちを超えます。
// Log Inequality 2 #![allow(non_snake_case)] //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); line.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } fn YesNo(b: bool) -> String { return if b { "Yes".to_string() } else { "No".to_string() } } //////////////////// process //////////////////// fn read_input() -> (u64, u64, u64) { let v = read_vec(); let a = v[0]; let b = v[1]; let c = v[2]; (a, b, c) } fn f(a: u64, b: u64, c: u64) -> bool { if a < c { true } else if c == 1 { false } else { let mut p = c; for _ in 1..b { if a / p < c { return true } p *= c } a < p } } fn main() { let (a, b, c) = read_input(); println!("{}", YesNo(f(a, b, c))) }