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: Wrong Answer)

#![allow(dead_code)]
use crate::scanner::Scanner;
fn main() {
    let mut scan = Scanner::new();
    let a = scan.read::<i64>();
    let b = scan.read::<i64>();
    let n = scan.read::<i64>();
    let mut ret = 0;
    for x in n / b * b..=n {
        chmax!(ret, a * x / b - a * (x / b));
    }
    println!("{}", ret);
}
mod scanner {
    use std::io::{stdin, BufReader, Bytes, Read, Stdin};
    use std::str::FromStr;
    pub struct Scanner {
        buf: Bytes<BufReader<Stdin>>,
    }
    impl Scanner {
        pub fn new() -> Scanner {
            Scanner {
                buf: BufReader::new(stdin()).bytes(),
            }
        }
        pub fn read_next<T: FromStr>(&mut self) -> Option<T> {
            let token = self
                .buf
                .by_ref()
                .map(|c| c.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect::<String>();
            token.parse::<T>().ok()
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_next().unwrap()
        }
        pub fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read::<T>()).collect()
        }
        pub fn chars(&mut self) -> Vec<char> {
            self.read::<String>().chars().collect()
        }
    }
}
mod macros {
    #[macro_export]
    macro_rules ! for_ { ( $ init : stmt ; $ cond : expr ; $ incr : expr , $ body : block ) => { $ init while $ cond { $ body $ incr ; } } ; }
    #[macro_export]
    macro_rules ! vecs { ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vecs ! ( $ ( $ dim ) ;* => $ init ) } ; ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vecs ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] } ; ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] } ; }
    #[macro_export]
    macro_rules! chmax {
        ( $ x : expr , $ y : expr ) => {
            if $x < $y {
                $x = $y;
                true
            } else {
                false
            }
        };
    }
    #[macro_export]
    macro_rules! chmin {
        ( $ x : expr , $ y : expr ) => {
            if $x > $y {
                $x = $y;
                true
            } else {
                false
            }
        };
    }
    #[macro_export]
    macro_rules ! assign { ( $ arr : ident $ ( [ $ a : expr ] ) + = $ right : expr ) => { unsafe { assign ! ( $ arr , $ ( [ $ a ] ) + , = , $ right , default ) ; } } ; ( $ arr : ident $ ( [ $ a : expr ] ) + += $ right : expr ) => { unsafe { assign ! ( $ arr , $ ( [ $ a ] ) + , += , $ right , default ) ; } } ; ( $ arr : ident $ ( [ $ a : expr ] ) + -= $ right : expr ) => { unsafe { assign ! ( $ arr , $ ( [ $ a ] ) + , -= , $ right , default ) ; } } ; ( $ arr : ident $ ( [ $ a : expr ] ) + |= $ right : expr ) => { unsafe { assign ! ( $ arr , $ ( [ $ a ] ) + , |= , $ right , default ) ; } } ; ( $ arr : ident $ ( [ $ a : expr ] ) + &= $ right : expr ) => { unsafe { assign ! ( $ arr , $ ( [ $ a ] ) + , &= , $ right , default ) ; } } ; ( $ arr : ident $ ( [ $ a : expr ] ) + ^= $ right : expr ) => { unsafe { assign ! ( $ arr , $ ( [ $ a ] ) + , ^= , $ right , default ) ; } } ; ( $ arr : ident $ ( [ $ a : expr ] ) + min $ right : expr ) => { unsafe { assign ! ( $ arr , $ ( [ $ a ] ) + , ^= , $ right , min ) ; } } ; ( $ arr : ident $ ( [ $ a : expr ] ) + max $ right : expr ) => { unsafe { assign ! ( $ arr , $ ( [ $ a ] ) + , ^= , $ right , max ) ; } } ; ( $ arr : expr , [ $ head : expr ] , $ op : tt , $ right : expr , default ) => { let head = $ head ; if 0 <= head as i64 && ( head as i64 ) < $ arr . len ( ) as i64 { let tmp = $ right ; *$ arr . get_unchecked_mut ( head as usize ) $ op tmp ; } } ; ( $ arr : expr , [ $ head : expr ] , $ op : tt , $ right : expr , min ) => { let head = $ head ; if 0 <= head as i64 && ( head as i64 ) < $ arr . len ( ) as i64 { let tmp = $ right ; *$ arr . get_unchecked_mut ( head as usize ) = std :: cmp :: min ( *$ arr . get_unchecked ( head as usize ) , tmp ) ; } } ; ( $ arr : expr , [ $ head : expr ] , $ op : tt , $ right : expr , max ) => { let head = $ head ; if 0 <= head as i64 && ( head as i64 ) < $ arr . len ( ) as i64 { let tmp = $ right ; *$ arr . get_unchecked_mut ( head as usize ) = std :: cmp :: max ( *$ arr . get_unchecked ( head as usize ) , tmp ) ; } } ; ( $ arr : expr , [ $ head : expr ] $ ( [ $ a : expr ] ) +, $ op : tt , $ right : expr , $ kind : ident ) => { let head = $ head ; if 0 <= head as i64 && ( head as i64 ) < $ arr . len ( ) as i64 { assign ! ( $ arr . get_unchecked_mut ( head as usize ) , $ ( [ $ a ] ) +, $ op , $ right , $ kind ) ; } } ; }
    #[macro_export]
    macro_rules! unwrap {
        ( $ arg : expr ) => {{
            let tmp = $arg;
            if tmp.is_none() {
                return;
            }
            tmp.unwrap()
        }};
    }
    #[macro_export]
    macro_rules! swap {
        ( $ a : expr , $ b : expr ) => {
            let tmp = $a;
            $a = $b;
            $b = tmp;
        };
    }
}