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 JavaScript (Node.js 12.16.1) (judge verdict: Wrong Answer)

"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[0].split(" ")[1]);
    const N = parseInt(arg[0].split(" ")[2]);
    
    // for(let i=1; i<=N; i++) {
    //     let temp = Math.floor((A * i) / B) - (A * Math.floor(i / B));
    //     console.log(temp)
    // }
    
    let answer = -10e5;
    
    // 0が2回出た時点でループ
    if(A < B) {
        let cnt = 0;
        
        for(let i=1; i<=N; i++) {
            let temp = Math.floor((A * i) / B) - (A * Math.floor(i / B));
            
            answer = Math.max(answer, temp);
            
            if(temp === 0) cnt++;
            if(cnt === 2) break;
        }
    } else {
    // 0が初めて出た時点でループ
        for(let i=1; i<=N; i++) {
            let temp = Math.floor((A * i) / B) - (A * Math.floor(i / B));
            
            answer = Math.max(answer, temp);
            
            if(temp === 0) break;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));