Problem:
Score : 400 points

Problem Statement

Given are integers A, B, and N.

Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.

Here floor(t) denotes the greatest integer not greater than the real number t.

Constraints

1 ≤ A ≤ 10^{6}

1 ≤ B ≤ 10^{12}

1 ≤ N ≤ 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B N

Output

Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.

Sample Input 1

5 7 4

Sample Output 1

2

When x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.

Sample Input 2

11 10 9

Sample Output 2

9

Solution in Rust (1.42.0) (judge verdict: Time Limit Exceeded)

use std::io::stdin;
use std::str::FromStr;
use std::cmp::max;
use std::cmp::min;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn read_str_as_char_vec() -> Vec<char> {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().chars().collect()
}

fn read_str_as_T<T>() -> T 
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().unwrap()
}

fn main() {
    let in_vec: Vec<usize> = read_line();
    let a = in_vec[0];
    let b = in_vec[1];
    let n = in_vec[2];

    let mut res = 0;
    for x in 0..=min(b, n) {
        let left = a * x / b;
        let right = a * (x / b);
        res = max(res, left - right);
    }

    println!("{}", res);


    //let temp = 1_000_000_000_000 - (1_000_000_000_000 % b);
//    let temp = n - (n % b) - 1;
    // let x:usize;
    // let left:usize;
    // let right:usize;
    // if n >= n % b + 1 {
    //     x = n - (n % b) - 1;
    //     left = (a * x) / b;
    //     right = a * (x / b);
    //     println!("AA");
    // } else {
    //     let x_1 = 1;
    //     let left_1 = (a * x_1) / b;
    //     let right_1 = a * (x_1 / b);

    //     let x_2 = n;
    //     let left_2 = (a * x_1) / b;
    //     let right_2 = a * (x_1 / b);

    //     if left_1 - right_1 < left_2 - right_2 {
    //         left = left_2;
    //         right = right_2;
    //     println!("BB");
    //     } else {
    //         left = left_1;
    //         right = right_1;
    //     println!("CC");
    //     }
    // }
    // println!("{}, {}", left, right);
    // println!("{}", left - right);
}