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 Go (1.14.1) (judge verdict: Time Limit Exceeded)

package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		log.Fatal(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func ansa(a, b float64, n, c int, ch chan int) {
	ans := 0
	for x := c; x <= n; x++ {
		if int(math.Floor(a*float64(x)/b)-a*math.Floor(float64(x)/b)) >= ans {
			ans = int(math.Floor(a*float64(x)/b) - a*math.Floor(float64(x)/b))
		}
	}
	ch <- ans
}
func main() {
	sc.Split(bufio.ScanWords)

	a := float64(getInt())
	b := float64(getInt())
	n := getInt()
	ans := 0
	chans := 0
	ch := make(chan int)
	go ansa(a, b, n, 0, ch)
	if n >= 1000000 {
		go ansa(a, b, n/2, 0, ch)
		go ansa(a, b, n, n/2, ch)
		chans = <-ch
		if chans > ans {
			ans = chans
		}
		chans = <-ch
		if chans > ans {
			ans = chans
		}
		close(ch)
		out(ans)
		os.Exit(0)
	}
	ans = <-ch
	close(ch)
	out(ans)
}