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



Sample input:
5 7 4


Sample output:
2

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# import numpy as np
# from itertools import *
# from collections import *

# S = input().split()
# N = int(input().split())
# K, N = [int(x) for x in input().split()]

A, B, N = [int(x) for x in input().split()]

nextN = N / 2
r = N / 2

n1 = nextN - r / 2
n2 = nextN
n3 = nextN + r / 2

while r > 100:

    print("r: ", r)


    c1 = (A * n1 / B) - (A * (n1 / B))
    c2 = (A * n1 / B) - (A * (n1 / B))
    c3 = (A * n1 / B) - (A * (n1 / B))

    m = max([c1, c2, c3])
    print("n: ", [n1, n2, n3])
    print("c: ", [c1, c2, c3])
    print()
    if m == c1:
        nextN = int(n1)
    elif m == c2:
        nextN = int(n1)
    else:
        nextN = int(n1)

    r /= 2

    n1 = nextN - r / 2
    n2 = nextN
    n3 = nextN + r / 2

n1 -= 200
n3 += 200
if int(n1) <= 0:
    n1 = 1
if int(n3) > N:
    n3 = N

m = 0

for x in range(int(n1), int(n3)+1):
    c = (A * x // B) - (A * (x // B))
    if c > m:
        m = c

print(m)

Submission status: Wrong Answer

Solution code:
import math
a,b,n=map(int,input().split())
c=math.floor((a*n)/b)-a*math.floor(n/b)
print(c)

Submission status: Wrong Answer

Solution code:
a, b , n = map(int, input().split())
def floor_abx(a, b, x):
    return int(a*x/b) - int(x/b)*a 
    
res = 0
for i in range(n+1-a, n+1):
    num = floor_abx(a, b, i)
    if res < num:
        res = num
print(res)

Submission status: Wrong Answer

Solution code:
import math
A, B, N = map(int, input().split())
t = N // B
if N % B == 0:
    a = max(1, N-1)
    b = N
    d = max(1,t*B-1)
    e = 1
else:
    a = max(1, t * B - 1)
    b = N
    d = max(1,N-1)
    e = 1

k = A * N // B
if A * N % B == 0:
    case = [a, b, max(min(B-1,N),1),d,e]
else:
    c = max(1,k*B//A+1)
    case = [a,b,c,max(min(B-1,N),1),d,e]

ans = 0
for i in case:
    ans = max(ans,math.floor(A*i/B)-A*math.floor(i/B))

print(ans)

Submission status: Wrong Answer

Solution code:
import math

A, B, N = map(int, input().split())

ans = 0
if N <= 5000000:
    for x in range(1, N+1):
        tmp = math.floor((A*x)/B)-A*(x//B)
        ans = max(ans, tmp)
else:
    if B <= N:
        ans = math.floor((A*(B-1))/B)-A*((B-1)//B)
    if A <= N:
        ans = math.floor((A*(A-1))/B)-A*((A-1)//B)

    for x in range(1, 600000):
        tmp = math.floor((A*x)/B)-A*(x//B)
        ans = max(ans, tmp)

    base = N//2-300000
    for x in range(base, base+600000):
        tmp = math.floor((A*x)/B)-A*(x//B)
        ans = max(ans, tmp)

    for x in range(N-600000, N+1):
        tmp = math.floor((A*x/B))-A*(x//B)
        ans = max(ans, tmp)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

a, b, n = map(int, input().split())

if n >= b:
    print(a-1)
else:
    print(math.floor(a*n/b)-a*math.floor(n/b))

Submission status: Wrong Answer

Solution code:
A,B,N = map(int, input().split())
ans = [-1]
for t in range(N):
    x = t + 1
    ansX = A*x//B-A*(x//B)
    if ansX == max(ans):
        break
    elif ansX != 0:
        ans.append(ansX)
print(max(ans))

Submission status: Wrong Answer

Solution code:
import math
a,b,n = map(int,input().split())
n_st = n
cnt = 0
if math.floor(a*n/b) - a*(math.floor(n/b)) == 0:
    while math.floor(a*n/b) - a*(math.floor(n/b)) == 0:
        n = n - 1
        cnt += 1
        
        if cnt == n_st:
            print(math.floor(a*n/b) - a*(math.floor(n/b)))
            break

        elif math.floor(a*n/b) - a*(math.floor(n/b)) != 0:
            print(math.floor(a*n/b) - a*(math.floor(n/b)))

else:
    print(math.floor(a*n/b) - a*(math.floor(n/b)))

Submission status: Wrong Answer

Solution code:
import math
import random

A,B,N = map(int,input().split())

def quick(x):
  pri = math.floor(A * x / B)
  lat = A * math.floor(x / B)
  return math.floor(pri - lat)

max = quick(N)
for i in range(50000):
  ran = math.floor(random.uniform(0, N))
  tem = quick(ran)
  if(max < tem):
    max = tem

print(max)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May  2 22:26:54 2020

@author: Kanaru Sato
"""

a,b,n = list(map(int,input().split()))

def floorspecial(x):
    u = int((a*x)/b)
    v = a*int(x/b)
    print(u-v)

if a == 1:
    print(0)
elif n < b:
    floorspecial(n)
else:
    p = int(n/b)*b
    p = p-1
    floorspecial(p)

Submission status: Wrong Answer

Solution code:
a, b , n= input().split() 
a = int(a)
b = int(b)
n = int(n)
if b > n :
    print(a*n//b)
else:
    max = 0
    for i in range(b,int(n)+1,1):
        r = (a*i // b) - a* (i//b)
        if r > max:
            max = r

    print(max)

Submission status: Wrong Answer

Solution code:
a, b, n = map(int, input().split())

x = 0
while x <= n:
    if (int(a*x/b) - int(a*(x-1)/b) + a*int(1/b)) >= 0 :
        x += 1
    else:
        break
if  n == (x-1) :
    x -= 1
print(int(a*x/b) - a*int(x/b))

Submission status: Wrong Answer

Solution code:
import math

a, b, n = map(int, input().split())
x = 1
s = 0

for i in range(n):
    i = i+1
    si = math.floor(a*i/b)-i*math.floor(i/b)
    if (s < si):
        s = si
        x = i
if(x == 1):
    print(0)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
A,B,N = map(int,input().split())
a = []
C = N // B

if C == 0:
  for x in range(1,N+1):
    D = x/B
    Y = int(A*D)-A*int(D)
    a.append(Y)
else:
  for x in range((C-1)*B+1,N+1):
    D = x/B
    Y = int(A*D)-A*int(D)
    a.append(Y)

answer = max(a)

print(answer)

Submission status: Wrong Answer

Solution code:
import math
a,b,n = map(int, input().split())

number = []
number.append(min(b, n))
current = b*2
while current-1 <= n:
    number.append(current-1)
    current += b

max_v = 0
for x in number:
    v = math.floor(a*x/b) - a * math.floor(x/b)
    max_v = max(v, max_v)

print(max_v)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	A,B,N = inputMap()

	maxs = 0
	conts = 12000000
	for x in range(N,0,-1):
		tmp = math.floor(A * x / B) - A * math.floor(x / B)
		conts -= 1
		if maxs < tmp:
			maxs = tmp
		if conts == 0:
			break

	print(maxs)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
a,b,n = map(int,input().split())
max=a-1
if n<b:
    max=int(a*n/b)-a*int(n/b)
print(max)

Submission status: Wrong Answer

Solution code:
def f1(a, b, x):
  return int(a * x / b)

def f2(a, b, x):
  return a * f1(1, b, x)

a, b, n = map(int, input().split())
result = 0

if n < b:
  for x in reversed(range(n + 1)):
    ans = f1(a, b, x)
    print(ans)    
    if ans > result:
      result = ans
    if ans < result:
      break
else:
  for x in reversed(range(b, n + 1)):
    ans = f1(a, b, x)-f2(a, b, x)
    if ans > result:
      result = ans
    if ans < result:
      break

print(result)

Submission status: Wrong Answer

Solution code:
a,b,N=map(int,input().split())
for i in range(1,N+2):
    d=((a*i)//b)-(a*(i//b))
    if(i>N):
        print(((a*(i-1))//b)-(a*((i-1)//b)))
        break

Submission status: Wrong Answer

Solution code:
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    a, b, n = map(int, input().split())
    l = 0
    r = n
    ans = math.floor(a*n/b) - a*math.floor(n/b)
    while(l+1 < r):
        x = (l+r)/2
        xx = math.floor(x)
        t = math.floor(a*xx/b) - a*math.floor(xx/b)
        if ans <= t:
            ans = t
            r = x
        else:
            l = x
        

    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import math
A, B, N = map(int, input().split())
t = N // B
if N % B == 0:
    a = max(1, N-1)
    b = N
    d = max(1,t*B-1)
    e = 1
else:
    a = max(1, t * B - 1)
    b = N
    d = max(1,N-1)
    e = 1

k = A * N // B
if A * N % B == 0:
    case = [a, b, max(min(B-1,N),1),d,e]
else:
    c = max(1,k*B//A+1)
    case = [a,b,c,max(min(B-1,N),1),d,e]

ans = 0
for i in case:
    ans = max(ans,math.floor(A*i/B)-A*math.floor(i/B))

Submission status: Wrong Answer

Solution code:
A,B,N = map(int, input().split())
import math
max = 0
for x in range(N):
    y = math.floor((A*x)/B) - A*math.floor(x/B)
    if(max<y):
        max = y

print(max)

Submission status: Wrong Answer

Solution code:
A, B, N = input().split()
A = float(A)
B = float(B)
N = float(N)
import math
value = math.floor(A*(B-1)/B)
max = 0
for x in range(int(N)):
  a = int(math.floor(A*x/B)-A*math.floor(x/B))
  if a > max:
    max = a
if N < B-1:
  print(a)
else:
  print(value)

Submission status: Wrong Answer

Solution code:
A,B,N = [int(i) for i in input().split()]
x = N
M = A*N//B
ans = -float("inf")

for _ in range(min([10**6,N])):
    s = (A*x)//B - A*(x//B)
    ans = max([ans,s])
    x -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
a, b, n = map(int, input().split())

def floor(x):
    return int(x)

if b<=n:
    print(a-1)
else:
    ans=floor(a*n/b)
    print(ans)

Submission status: Wrong Answer

Solution code:
a,b,n=map(int,input().split())
if a <= b:
    if n > b:
        ans=(a*(b-1))//b
    else:
        ans=(a*n)//b - a*(n//b)
else:
    if n > b:
        ans=(a*(b-1))//b
    else:
        ans=(a*n)//b - a*(n//b)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys

A, B, N = [int(x) for x in stdin.readline().rstrip().split()]
# N, M = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
ans = int((A*N)/B)-A*int(N/B)
if N >= B:
    for i in reversed(range(N)):
        if i % B == 0:
            ans1 = int((A*(i-1))/B)-A*int((i-1)/B)
            break
else:
    ans1 = ans
if N > 100000:
    p = N-100000
else:
    p = 1
for i in range(p, N+1):
    temp = int((A*i)/B)-A*int(i/B)
    if temp > ans:
        # print(i)
        ans = temp

print(max(ans, ans1))

Submission status: Wrong Answer

Solution code:
import math

a, b, n = map(int, input().split())
def f(x):
    return (a * x) // b - a * (x // b)

left, right = 1, n
while right > left + 10:
    mid1 = (right * 2 + left) // 3 + 1
    mid2 = (right + left * 2) // 3
    if f(mid1) <= f(mid2):
        # 上限を下げる（最小値をとるxはもうちょい下めの数だな）
        right = mid2
    else:
        # 下限を上げる（最小値をとるxはもうちょい上めの数だな）
        left = mid1
listalt = []
for i in range(left, right + 1):
    listalt.append(f(i))
listalt.append(f(1))
listalt.append(f(n))
print(max(listalt))

Submission status: Wrong Answer

Solution code:
import math

def main():
  a, b, n = map(int,input().split())
  mod = n
  if n % b == 0:
    mod -= 1
  ans = math.floor(a * mod / b) - a * math.floor(mod / b)
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import math

a = list(map(int, input().split()))
A = a[0]
B = a[1]
N = a[2]

ans = math.floor(A*N/B)-A*math.floor(N/B)
ans_2 = math.floor(A*(N-1)/B)-A*math.floor((N-1)/B)

if ans>=ans_2:
  print(ans)
else:
  print(ans_2)

Submission status: Wrong Answer

Solution code:
import math
A,B,N= map(int,input().split())

  

max=0
for i in reversed(range(1, N+1)):
  y=float(math.floor(A*i/B))-A*float((math.floor(i/B)))
  if max < y :
    max=y
print(max)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, N: int):
    if N < B:
        x = N
    else:
        md = N % B
        x = N - (md + 1)
    # print(md, x)
    return int((A*x)/B) - A * int(x/B)

    # m = -1
    # for i in range(N+1):
    #     x = i
    #     m = max([m, int((A*x)/B) - A * int(x/B)])
    # return m


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    # N = pow(10, 9)
    print(solve(A, B, N))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import floor
A, B , N = map(int, input().split())
List = []
for x in range(N-3,N+1):
    Answer = floor((A*x)/B) - (A*floor(x/B))
    List.append(Answer)
# print(List)
print(max(List))

Submission status: Wrong Answer

Solution code:
A, B, N = [int(i) for i in input().split()]

def f(x: int) -> int:
    return (A * x) // B - A * (x // B)

res = 0
for x in range(N, 0, -1):
    tmp = f(x)
    if res <= tmp:
        res = tmp
    else:
        print(res)
        break
else:
    print(res)

Submission status: Wrong Answer

Solution code:
A, B, N = map(int,input().split())

def fl(i):
  return ((A * i) // B) - (A * (i // B))

if B <= N:
  print(int(fl(B / A * (A - 1))))
else:
  print(int(fl(N)))

Submission status: Wrong Answer

Solution code:
import math

a,b,n=map(int,input().split())
maxtemp=0
teisuu=10000000
def funcsum(x):

    return math.floor(a*x/b)-(a*math.floor(x/b))

for i in range(n):
    if i>teisuu:
        break
    temp=int(n/2)-i
    maxtemp=max(maxtemp,funcsum(temp))

for i in range(n):
    if i>teisuu:
        break
    temp=int(n/2)+i
    maxtemp=max(maxtemp,funcsum(temp))
print(maxtemp)

#items=[int(i) for i in input().split()]


#items=[i for i in range(n+1)]

Submission status: Wrong Answer

Solution code:
ABN = list(map(int,input().split()))
A = ABN[0]
B = ABN[1]
N = ABN[2]

max_of_x = min(B, N)
max = int(A*max_of_x/B)

for x in range(max_of_x, N+1):
    score = int(A*max_of_x/B) + A*int(x/B)
    if score>max:
        max = score
        
print(max)

Submission status: Wrong Answer

Solution code:
import math
A,B,N = map(int,input().split())
def equation(i,j,k):
    return math.floor(i*k/j)-i*math.floor(k/j)
if N<B:
    print(math.floor(A*N/B)-A*math.floor(N/B))
else:
    top = N
    bottom = 0
    now = 0
    while top - bottom >1 :
        middle = (top+bottom)/2
        if equation(A,B,middle) <= now:
            bottom = middle
        else:
            top = middle
            now = equation(A,B,middle)
    print(now)

Submission status: Wrong Answer

Solution code:
import math 
 
a,b,n = map(int,input().split())

if b > n:
    ans = math.floor(a*n/b) - a*math.floor(n/b)
    print(int(ans))
    exit()

c = math.floor(n/b)*b-1
d = n-1
temp1 = math.floor(a*c/b) - a*math.floor(c/b)#一番大きい倍数の前
temp2 = math.floor(a*n/b) - a*math.floor(n/b)#とれる最大のｎ
temp3 = math.floor(a*d/b) - a*math.floor(d/b)#nがｂの倍数だった時

print(int(max(temp1,temp2,temp3)))

Submission status: Wrong Answer

Solution code:
a, b, n = map(int, input().split())

if n >= b:
    ans = a*(n - n%b - 1)//b - a*(n - n%b - 1)//b
else:
    ans = a*n//b - a*(n//b)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
a, b, n = map(int, input().split())

if n >= b:
    x = b*math.floor(n/b) - 1
else:
    x = n

print(math.floor(a*x/b) - a*math.floor(x/b))

Submission status: Wrong Answer

Solution code:
A, B, N = map(int,input().split())
score = 0
for i in range(N):
    x = i+1
    val = int(A*x/B) - int(x/B)
    if(val > score):
        score = val
print(score)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	A,B,N = inputMap()

	maxs = 0
	conts = 0
	for x in range(N,0,-1):
		tmp = math.floor(A * x / B) - A * math.floor(x / B)
		conts += 1
		if maxs < tmp:
			maxs = tmp
		if conts == 12000000:
			break

	print(maxs)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
num = input()
num = num.split(' ')

A = int(num[0])
B = int(num[1])
N = int(num[2])

import math
import sys

min = sys.float_info.max
for x in range(N + 1):
  ans = math.floor(A*x/B) - A * math.floor(x/B)

  if ans < min:
    min = ans

print(min)

Submission status: Wrong Answer

Solution code:
a, b, n = map(int, input().split())
x = (((a*n)//b)*b+a-1)//a
def calc(x):
    return int(a*x/b)-a*int(x/b)
ans = 0
for i in range(max(0, x-10**7), min(x+10**7, n+1)):
    if ans<calc(i):
        ans = calc(i)
print(max(ans,0))

Submission status: Wrong Answer

Solution code:
import  math
A, B, N = map(int, input().split())

aaa = math.floor(A * N / B) - A * math.floor(N / B)

v = N % B
v += 1
bbb = 0
if N - v >= 1:
    bbb = math.floor(A * (N - v) / B) - A * math.floor((N - v)/ B)
ccc = 0
if B - 1 >= 1:
    ccc = math.floor(A * (B - 1) / B) - A * math.floor((B - 1)/ B)

print(max(aaa, bbb, ccc))

Submission status: Wrong Answer

Solution code:
def main():
    import math

    A, B, N = map(int, input().split())

    if (N >= B):
        syou = N // B
    else:
        syou = 0

    if (syou == N / B):
        ## ans = syou * (A - 1) + 1
        ans = math.floor(A * syou) - A * syou
        # ans = syou * (A - 1)

    else:
        ans = syou * (A - 1)
        mod = N / B - N // B
        y = 1 - mod
        cnt = 0
        for i in range(1, A):
            num = i / A
            if (num > y):
                cnt = A - i
                break
        ans += cnt

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a,b,n = map(int,input().split())
ans = 0

if a <= n:
    print(a-1)
else:
    for i in range(n+1,n-a,-1):
        ans = max(ans,(a*i)//b - a*(i//b))
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
a, b, n = map(int, input().split())

ans = (math.floor(a*n/b) - a * math.floor(n/b))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

a = listA[0][0]
b = listA[0][1]
n = listA[0][2]

old = 0
for x in range(n):
  current = math.floor(a*x/b)-a*math.floor(x/b)
  if old < current:
    old = current
    
print (old)

Submission status: Wrong Answer

Solution code:
A,B,N=map(int,input().split())
ans=0
print(int(A*(N)/B)-A*int((N)/B))
if B>=N:
    for i in range(0,10**6):
        x=N-i
        if x<0:
            break
        tmp=int(A*x/B)-A*int(x/B)
        ans=max(ans,tmp)
    #print(ans)
elif B<N:
    for i in range(0,10**6):
        x=N-i
        if x<0:
            break
        tmp=int(A*x/B)-A*int(x/B)
        ans=max(ans,tmp)
    for i in range(0,10**6):
        x=B-i
        if x<0:
            break
        tmp=int(A*x/B)-A*int(x/B)
        ans=max(ans,tmp)
    #print(ans)

Submission status: Wrong Answer

Solution code:
A,B,N = map(float,input().split())

if N%B == 0:
    tmp = (N//B)*B + (N%B)
    print(int(A*(tmp-1)/B) - A*int((tmp-1)/B))
else:
    tmp = (N//B)*B + (N%B)
    print(int(A*(tmp)/B) - A*int((tmp)/B))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
A = a[0]
B = a[1]
N = a[2]
ans = 0
an = 0

if N<=10**6:
  for i in range(N+1):
    an = int(A*i/B)-A*int(i/B)
    if an >= ans:
      ans = an
    else:
      ans = ans

else:
  for i in range(N-10**6,N+1):
    an = int(A*i/B)-A*int(i/B)
    if an >= ans:
      ans = an
    else:
      ans = ans

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import pprint
import math

a, b, n = map(int, input().split())

s = min(n, b)
ans = math.floor(a * s / b) - a * math.floor(s / b)

print(ans)

Submission status: Wrong Answer

Solution code:
A, B, N = map(int, input().split())


if N > B:
    X = (A*(B-1)) // B
    Y = A * ((B-1)//B)
    print(X-Y)
else:
    X = (A*N) // B
    Y = A * (N//B)
    print(X-Y)

Submission status: Wrong Answer

Solution code:
a, b, n = map(int, input().split())
x = 0

if n % b == 0:
  x = n - 1
else:
  x = n

ans = (a * x) // b - a * (x // b)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import random

A,B,N = map(int,input().split())

def quick(x):
  pri = math.floor(A * x / B)
  lat = A * math.floor(x / B)
  return math.floor(pri - lat)

max = 0
for i in range(10000):
  ran = math.floor(random.uniform(0, N))
  tem = quick(ran)
  if(max < tem):
    max = tem

print(max)

Submission status: Wrong Answer

Solution code:
import math
import sys
a, b, n = map(int, input().split())

nibu_max = n
nibu_min = 1
nibu_mid = (1 + n) // 2


for i in range(int(math.log(n, 2)) + 1):
    sss_max = int(a * nibu_max / b) - a * int(nibu_max / b)
    sss_mid = int(a * nibu_mid / b) - a * int(nibu_mid / b)
    sss_min = int(a * nibu_min / b) - a * int(nibu_min / b)

    if sss_max > sss_mid:
        nibu_min = nibu_mid + 1
        nibu_mid = int((nibu_max + nibu_min) / 2)
    elif sss_mid < sss_min:
        nibu_max = nibu_mid - 1
        nibu_mid = int((nibu_max + nibu_min) / 2)
    else:
        print(int(a * nibu_mid / b) - a * int(nibu_mid / b))
        sys.exit()
print(int(a * nibu_mid / b) - a * int(nibu_mid / b))

Submission status: Wrong Answer

Solution code:
import math

a,b,n = map(int, input().split())
tmp = int(n/b)
result = 0
if tmp != 0:
    result = b*tmp - 1
else:
    result = n
if result + b <= n: result += b
print(math.floor(a*result/b) - a*math.floor(result/b))

Submission status: Wrong Answer

Solution code:
A,B,N= list(map(int, input().split()))
ma=0
if(B>=N):
    for i in range(N):
        a=int(A*i/B)-A*int(i/B)
        if(ma<a):
            ma=a
if(B<N):
    for i in range(B):
        a=int(A*i/B)-A*int(i/B)
        if(ma<a):
            ma=a
print(ma)

Submission status: Wrong Answer

Solution code:
def main():
    max = 0
    a, b, n = map(int, input().split())
    if n < b:
        max = int(a*n/b)
    else:
        _ = n//b
        x = b*_-1
        for i in range(x, n+1, b):
            ans = int(a*i/b) - a*int(i/b)
            if max < ans:
                max = ans
        ans = int(a*n/b)
        if max < ans:
            max = ans

    return max

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
import sys

li=list(map(int,sys.stdin.readline().split()))
a=li[0]
b=li[1]
n=li[2]

for x in range(0,n+1):
  c=int((a*x)/b)
  d=int(x/b)
  e=int(c-a*d)
  list=[]
  list.append(e)
  
print(max(list))

Submission status: Wrong Answer

Solution code:
a, b, n = map(int, input().split())
print(int(n % b // (b / a)))