Problem:
Score : 400 points

Problem Statement

You are given integers N and M.

Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

N \leq M \leq 10^9

Input

Input is given from Standard Input in the following format:

N M

Output

Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.

Sample Input 1

3 14

Sample Output 1

2

Consider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common divisor is 2, and this is the maximum value.

Sample Input 2

10 123

Sample Output 2

3

Sample Input 3

100000 1000000000

Sample Output 3

10000

Solution in Rust (1.42.0) (judge verdict: Wrong Answer)

#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let mut M: usize = read();
    if M % N == 0 {
        println!("{}", M / N);
        return;
    }
    use std::collections::HashMap;
    let mut primeFactor = HashMap::new();
    for i in 2..((M as f64).sqrt().ceil() as usize) {
        while M % i == 0 {
            let entry = primeFactor.entry(i).or_insert(0);
            *entry += 1;
            M /= i;
        }
    }
    if M != 1 {
        let entry = primeFactor.entry(M).or_insert(0);
        *entry += 1;
    }
    let mut ans = 1;
    let mut keys: Vec<_> = primeFactor.keys().collect();
    keys.sort();
    let mut split_key = None;
    for key in keys {
        let mut val = key.pow(*primeFactor.get(&key).unwrap());
        if split_key.is_none() && val >= N {
            split_key = Some(key);
            val /= key * std::cmp::max(N / key, 1);
        }
        ans *= val;
    }
    if split_key.is_none() {
        ans = 1;
    }
    println!("{}", ans)
}