use std::collections::HashMap; #[allow(unused_macros)] macro_rules! scan { () => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().to_string() } }; (;;) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().split_whitespace().map(|s| s.to_string()).collect::>() } }; (;;$n:expr) => { { (0..$n).map(|_| scan!()).collect::>() } }; ($t:ty) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().parse::<$t>().unwrap() } }; ($($t:ty),*) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( $(iter.next().unwrap().parse::<$t>().unwrap(),)* ) } }; ($t:ty;;) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse::<$t>().unwrap()) .collect::>() } }; ($t:ty;;$n:expr) => { (0..$n).map(|_| scan!($t;;)).collect::>() }; ($t:ty; $n:expr) => { (0..$n).map(|_| scan!($t) ).collect::>() }; ($($t:ty),*; $n:expr) => { (0..$n).map(|_| scan!($($t),*) ).collect::>() }; } fn main() { let (n, k) = scan!(usize, i64); let mut m = n; let mut map = HashMap::new(); for i in 2.. { while m % i == 0 { m /= i; *map.entry(i).or_insert(0) += 1; } if m == 1 { break; } } let mut candidates = (1..n) .map(|i| { let mut m = i; let mut map0 = HashMap::new(); for j in 2.. { while m % j == 0 { m /= j; *map0.entry(j).or_insert(0) += 1; } if m == 1 { break; } } let mut same = 0; for (key, num) in &map { same += num.min(map0.get(&key).unwrap_or(&0)); } (same, map0.iter().fold(1, |s, (_, num)| s * (num + 1)), i) }) .filter(|&(same, _, _)| same >= k) .collect::>(); candidates.sort_by_key(|(_, k, _)| -k); let m = candidates[0].1; println!( "{}", candidates .iter() .filter(|&(_, k, _)| *k == m) .min_by_key(|(_, _, n)| n) .unwrap() .2 ) }