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:
# -*- 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 = 10000
	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

	conts = 11190000
	for x in range(A,N):
		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:
from math import gcd
A,B,N = list(map(int,input().split()))
ans = 0
lcm = A*B//gcd(A,B)
if N < 2*10**6:
    for x in range(N+1):
        ans = max(ans,(A*x//B)-A*(x//B))
else:
    for x in range(10**6+2):
        ans = max(ans,(A*x//B)-A*(x//B))
    for x in range(N,N-10**6,-1):
        ans = max(ans,(A*x//B)-A*(x//B))
    if lcm <= N:
        ans = max(ans,(A*(lcm-1)//B)-A*((lcm-1)//B))
        tmp = (N//lcm)*lcm
        ans = max(ans,(A*(tmp-1)//B)-A*((tmp-1)//B))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
a,b,n = map(int,input().split())
ans = 0
al = []
    
for i in range(n,-1,-1):
    t = (a*i)//b
    t2 = a*(i//b)
    ans = t-t2
    al.append(ans)
    if len(al) > 99:
        if al[-1] <= al[-100]:
            break
if max(al) < 0:
    print(0)
else:
    print(max(al))

Submission status: Wrong Answer

Solution code:
import math
I = input().split()
A = int(I[0])
B = int(I[1])
N = int(I[2])
def fl(x):
    return math.floor((A*x)/B) - A*math.floor(x/B)

An =fl(N)
    
if B <= N :
    for i in range(B,N) :
        if i >= B+1 and fl(i) <= fl(i-1) :
            An = fl(i-1)
            

print(str(An))

Submission status: Wrong Answer

Solution code:
def main():
    a, b, n = [int(e) for e in input().split()]

    if n > b:
        print(a * b // b)
        exit()

    print(a * n // b)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

answer = 0
for y in range(b):
    x = (n - b + y) + 1
    result = int(a * x/b) - a * int(x/b)
    if result > answer:
      answer = result

print(answer)

Submission status: Wrong Answer

Solution code:
from math import floor

a, b, n = [int(x) for x in input().split()]
result = []

for x in range(0, n+1):
    value = floor(a*x/b) - a * floor(x/b)
    result.append(value)

print(result)
print(max(result))

Submission status: Wrong Answer

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

max_s = []
j = 0
if n > 10**6:
    for i in range(n,0,-1):
        j += 1
        if j == int(10**6):
            break
        else:
            num = int((a*i)/b) - a*int(i/b)
            max_s.append(num)
    print(max(max_s))
else:
    for i in range(n,0,-1):
        j += 1
        if j == int(10**6):
            break
        else:
            num = int((a*i)/b) - a*int(i/b)
            max_s.append(num)
    print(max(max_s))

Submission status: Wrong Answer

Solution code:
import math
A, B, N = map(int,input().split())
f = math.floor((A*N)/B)
b = A * math.floor(N/B)
print(f-b)

Submission status: Wrong Answer

Solution code:
import math
abn = list(map(int, input().split()))
a = abn[0]
b = abn[1]
n = abn[2]
ans = -100000000
for x in range(n + 1):
  val: int = math.floor(a * x / b) - a * math.floor(x / b)
  if val > ans:
    ans = val
print(val)

Submission status: Wrong Answer

Solution code:
import math
A,B,N = [int(i)for i in input().split()]
tmpmax=0
for i in range(N+1):
  tmp=math.floor(A*i/B)-A*math.floor(i/B)
  if tmp > tmpmax:
    tmpmax = tmp
  elif tmp < tmpmax:
    continue
  elif tmp == tmpmax:
    break
print(tmpmax)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


num = list(map(int, input().split()))
a = num[0]
b = num[1]
n = num[2]
x = (int(n/b) + 1) * b - 1
max_num = 0
while x % b != 0:
    new_num = f(a, b, x)
    if max_num < new_num:
        max_num = new_num
    x -= 1
print(max_num)

Submission status: Wrong Answer

Solution code:
A, B, N = map(int, input().split())
if N < B:
    print(A*N//B)
else:
    l = [(A*i//B)-(A*(i//B)) for i in range(N-5, N+1)]
    print(max(l))

Submission status: Wrong Answer

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

lo = 1
hi = N

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

ans = 0
if B-1<=N:
    ans = f(B-1)

while hi > lo :
    if f(lo) <= f(hi):
        mid = (lo + hi) // 2
        if f(mid)<=f(mid+1):
            lo = mid+1
        else:
            lo = mid
    else:
        mid = -(-(lo + hi) // 2)
        hi = mid

ans = max(ans,f(lo),f(N-1),f(B*N//B-1))-1

print(ans)

Submission status: Wrong Answer

Solution code:
a, b, n = map(int, input().split())
max_int = 0
if a != b:
    for i in range(n, n-max(int(b/a), int(a/b))-1, -1):
        tmp = int((a*i)/b) -a * int(i/b)
        #print(tmp)
        if max_int < tmp:
            max_int = tmp
        #print(i)

print(max_int)

Submission status: Wrong Answer

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

max = (a*2)//b - a*(2//b)

for i in range(n,2):
    if (a*i)//b - a*(i//b) >= max:
        max = (a*i)//b - a*(i//b)

print(max)

Submission status: Wrong Answer

Solution code:
from math import floor
A,B,N = map(int,input().split())
#"""
if N < B:
    print(max(floor(A*N/B)-A*floor(N/B),floor(A*(N-1)/B)-A*floor((N-1)/B)))
else:
    print(max(floor(A*N/B)-A*floor(N/B),floor(A*B/B)-A*floor(B/B),floor(A*(B-1)/B)-A*floor((B-1)/B),floor(A*(N-1)/B)-A*floor((N-1)/B),floor(A*(B+1)/B)-A*floor((B+1)/B)))
#"""

Submission status: Wrong Answer

Solution code:
import math

a, b, n = (int(x) for x in input().split())

ans = 0

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

if a == b :
    ans = math.floor(a * (a - 1) / b) - a * math.floor((a - 1) / b)

if b < a :
    # for x in range(n + 1):
    #     temp = math.floor(a * x / b) - a * math.floor(x / b)

    #     if ans < temp :
    #         ans = temp     

    for x in range(b - 1, n + 1, b):
        # print(x)
        temp = math.floor(a * x / b) - a * math.floor(x / b)
        # print(temp)
        if ans <= temp :
            ans = temp

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math
A,B,n=map(int,input().split())
sum=0
x=n
while x!=0:
	ans=math.floor(A*x/B)-A*math.floor(x/B)
	if sum<ans:
		sum=ans
		x-=1
	else:	
		break
print(sum)

Submission status: Wrong Answer

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

def function(x, a=a, b=b):
    return int(a * x / b) - a * int(x / b)

ans = function(1)
for i in (1, n):
    if i * b - 1 > n:
        ans = max(ans, function(n))
        break
    ans = max(ans, function(i * b - 1))

print(max(ans, function(n)))

Submission status: Wrong Answer

Solution code:
a, b, n = map(int, input().split())
ans = []
for i in range(n//b + 1):
    x = min((n//b + 1)*b - 1, n)
    ans.append(int(a*x/b) -a*int(x/b))
print(max(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
a, b, n = map(int, input().strip().split())
if b<n:
    x=n
elif n % b <= n%(b/a):
    x=n-n%b-1
elif n%(b/a)+(b/a)>=n%b:
    x=n-n%b-1
else:
    x=n
print(math.floor(a*x/b)-a*math.floor(x/b))

Submission status: Wrong Answer

Solution code:
# abc165_d.py
A, B, N = map(int,input().split())
ans = -100000000000
pre = 10**9
ans = 0

for i in range(min(A,B,N)+1):
    t = (A*i) // B - A * (i//B)
    if pre < ans :
        break
    if ans < t:
        ans = t
    pre = t
print(ans)

Submission status: Wrong Answer

Solution code:
import math
A, B, N = [int(x) for x in input().split()]
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math

s = input().split()
n = int(s[2])
list=[]
for i in  range(int(n)):
    i+=1
    list.append(math.floor(int(s[0])*i/int(s[1]))-int(s[0])*math.floor(n/int(s[1])))

print(max(list))

Submission status: Wrong Answer

Solution code:
import math
import sys
a,b,n = map(int, input().split())
ans=0
if n<b:
    ans=math.floor(a*n/b)-a*math.floor(n/b)
    print(ans)
    sys.exit()
else:
    for i in range(b,n+1):
        tmp=math.floor(a*i/b)-a*math.floor(i/b)
        if ans<tmp:
            ans=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,n=map(int,input().split())
import math
if n<b-1:
    m=math.floor(a*n/b)
else:
    e=n//b
    n=b*(e-1)
    m=math.floor(a*n/b)-a*(math.floor(n/b))
print(m)

Submission status: Wrong Answer

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

ans = 0
i = 0
while True:
    i += max(1, B//A)
    if i > N:
        break
    tmp = ((A*i)//B) - (A*(i//B))
    if tmp > ans:
        ans = tmp
    else:
        break
        
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math

lines = sys.stdin.readlines()

X = lines[0].split(' ')
A = int(X[0])
B = int(X[1])
N = int(X[2])

m = A // B
j = A % B

if N >=B-1:
    print(m*(B-1)-1+j)
else:
    k = B-N
    print(j+m*N-math.ceil(j*k/B))

Submission status: Wrong Answer

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

def binary_search():
    low = 0
    high = n

    m = 0

    while low <= high:
        mid = (low + high) // 2

        l = int(a*low/b) - a * (int(low/b))
        h = int(a*high/b) - a * (int(high/b))

        m = max(m, h, l)

        if h > l:
            high = mid - 1
        else:
            low = mid + 1

    return m


print(binary_search())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
a, b, n = map(int, input().split())
x= int((1-a)/b)
max = 0
while x < n:
    t1 = int(math.floor((a*x)/b))
    t2 = int(a * math.floor(x/b))
    t3 = t1 - t2
    x+=1
    if(t3 > max):
        max = t3
print(max)

Submission status: Wrong Answer

Solution code:
import math
A,B,N=map(int,input().split())
if A>0:
    if B>0:
        x=N
    else:
        x=0
elif A<0:
    if B >0:
        x=0
    else:
        x=0
        
ans=math.floor(A*x/B)-A*math.floor(x/B)

print(ans)

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 = 100000
	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

	conts = 11900000
	for x in range(A,N):
		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:
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:
  result = f1(a, b, n)
else:
  result = f1(a, b, n)-f2(a, b, n)
    
 
print(result)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, sqrt, factorial, gcd
def main():
    a, b, n = map(int, input().split())
    mx = 0

    if b <= n:
        for x in range(b-1, n+1, b):
            yd = (x/b)-floor(x/b)
            if yd > mx:
                mx = yd
    else:
        mx = n
    ans = floor(a*mx/b)-a*floor(mx/b)
    print(ans)

    # li = [(x/b)-floor(x/b) for x in range(1, n+1)]
    # #yd = (x/b)-floor(x/b)
    # x = li.index(max(li))+1
    # ans = floor(a*x/b)-a*floor(x/b)
    # print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

lo = 1
hi = N

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

ans = 0
if B-1<=N:
    ans = f(B-1)

while hi > lo :
    if f(lo) <= f(hi):
        mid = (lo + hi) // 2
        if f(mid)<=f(mid+1):
            lo = mid+1
        else:
            lo = mid
    else:
        mid = -(-(lo + hi) // 2)
        hi = mid

ans = max(ans,f(lo),f(N-1),f(B*N//B-1))+1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
MOD = 1000000007

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


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

if A == B:
    if N%2:x = N//A - 1
    else:x = N//A
    print(f(x))

else:
    res = 0
    left = 0
    right = N

    left_res = 0
    right_res = 0

    while (left+1) != right:
        left_res = f(left)
        right_res = f(right)
        mid = (right+left)//2
        if left_res > right_res:
            right = mid
        else:
            left = mid

    print(max(f(left),f(right)))

Submission status: Wrong Answer

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

def calc(x):
    # print(a, b, x)
    return (a*x)//b - a*(x//b)

res = 0

for i in range(1, min(a + 1, n)):
    print(i)
    res = max(res, calc(i))
    print(res)

print(res)

Submission status: Wrong Answer

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

def f(x):
    return math.floor(A * x / B) - A * math.floor(x / B)

high = N
low = 1
while high - low > 1:
    mid_left = high / 3 + low * 2 / 3
    mid_right = high * 2 / 3 + low / 3
    # print(mid_left, mid_right)
    if f(mid_left) > f(mid_right):
        high = mid_right
    else:
        low = mid_left
print(int(f(high)))

Submission status: Wrong Answer

Solution code:
a,b,n=map(int,input().split())
'''
lst=[]
for i in range(n+1):
    now=int(a*i/b)-a*int(i/b)
    lst.append(now)
print(max(lst))
'''
now=0
if n>=b:
    if n//b>=500000:
        ans=int(a*(n-1)/b)-a*int((n-1)/b)
        ans2=int(a*n/b)-a*int(n/b)
        for i in range(0,n//b+1,100000):
            ans3=int(a*(i*b-1)/b)-a*int((i*b-1)/b)
            now=max(now,ans3)
        print(max(ans,ans2,now))
        exit()
    ans=int(a*(n-1)/b)-a*int((n-1)/b)
    ans2=int(a*n/b)-a*int(n/b)
    for i in range(n//b+1):
        ans3=int(a*(i*b-1)/b)-a*int((i*b-1)/b)
        now=max(now,ans3)
    print(max(ans,ans2,now))

else:
    ans=int(a*(n)/b)-a*int((n)/b)
    print(max(ans,0))

Submission status: Wrong Answer

Solution code:
import sys

def formula(A, B, x):
    return (A * x) // B - A * (x // B)

# print('input >>')
# print('-----output-----')

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

ans = formula(A, B, X)

for x in range(X+1, X+1-1000000, -1):
    f = formula(A, B, X)
    if f > ans:
        print(f)
        sys.exit()

print(ans)

Submission status: Wrong Answer

Solution code:
from  math import floor
def cal(x):
    return floor((a*x)/b) - a*floor(x/b)
a, b, n = map(int, input().split())
ans = 0
if 0 < b - 1< n:
    ans = max(cal(b-1),cal(b-2))
print(max(ans,cal(n),0))

Submission status: Wrong Answer

Solution code:
import math

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

for x in range(int(n), int(n-10), -1):
    n = math.floor(a*x/b) - a * math.floor(x/b)
    # print(n)
    if ans <= n:
      ans = n
  
print(ans)

Submission status: Wrong Answer

Solution code:
A, B, N = [int(i) for i in input().split(" ")]
ans = 0
idx = 0
for x in range(1, A+1):
    #print(x, A*x//B, A*(x//B), A*x//B-A*(x//B))
    if ans < A*x//B-A*(x//B):
        idx = x
    ans = max(ans, A*x//B-A*(x//B))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
A,B,N = (int(x) for x in input().split())
a = (N//B)*B-1
if a <= 0:
  ans = math.floor(A*N/B) - A*math.floor(N/B)
else:
  ans = math.floor(A*a/B) - A*math.floor(a/B)
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 = max(math.floor(a * s / b) - a * math.floor(s / b), 0)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def target(x):
    return (A * x) // B - A * (x // B)


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

left = 1
right = N

while right - left > 1:
    mid = (left + right) >> 1
    y = target(mid)
    prv = target(mid - 1)
    nxt = target(mid + 1)
    if prv <= y <= nxt:
        left = mid
    else:
        right = mid


print(target(right))

Submission status: Wrong Answer

Solution code:
A, B, N = map(int,input().split())
if(B-A < N) :
 cal = int((A*N)/B) - A*int(N/B)
 print(cal)
else :
 max = 0
 i=N
 while(1):
  cal = int((A*i)/B) - A*int(i/B)
  if(cal > max):
   max =cal
  i += -1
  if(i < 0):
   print(max)
   break;

Submission status: Wrong Answer

Solution code:
import math
A, B, N = map(int, input().split())
 
if N <B:
	print(math.floor(A*N/B))
	exit()
 
if N == B:
	print(0)
	exit()

k = []
 
for i in range (1, int(math.floor(N/B)+1)):
	k.append(i*B-1)
 
k.append(N)
print(k)
 
boom=0
 
for i in range (0, len(k)):
	p = math.floor(A*k[i]/B)-A*math.floor(k[i]/B)
	if p> boom:
		boom = p
 
print(boom)

Submission status: Wrong Answer

Solution code:
import math

a, b, n = map(int, input().split())
li = []
for x in range(n, n+1):
    an = math.floor(a*x//b) - a * math.floor(x//b)
    li.append(an)
print(max(li))

Submission status: Wrong Answer

Solution code:
import math

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

if b <= a:
    if n >= b:
        x = b - 1
        print(math.floor(a * x / b))
    elif n < b:
        x = n
        print(math.floor(a * x / b))
elif b > a:
    if n >= b:
        x = math.ceil(n / b) - 1
        print(math.floor(a * x / b) - a * math.floor(x / b))
    elif n < b:
        x = n
        print(math.floor(a * x / b))

Submission status: Wrong Answer

Solution code:
import math
from math import floor
A,B,N = map(int,input().split())
maxi = 0
Npower = 0
diff = 0
S = N
while S/10 >= 1:
    Npower += 1
    S /=10
if Npower >= 7:
    for i in range(0,10**6+10**5):
        maxi = max(floor((A*i)/B)-A*floor(i/B),maxi)
    for i in range(N-2*10**6,N+1):
        maxi = max(floor((A*i)/B)-A*floor(i/B),maxi)
else:
    for i in range(0,N+1):
        maxi = max(floor((A*i)/B)-A*floor(i/B),maxi)
print(max(maxi,0))

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(int(A*(tmp-1)/B) - A*int((tmp-1)/B)))
else:
    tmp = (N//B)*B + (N%B)
    print(int(int(A*(tmp)/B) - A*int((tmp)/B)))

Submission status: Wrong Answer

Solution code:
import math
A,B,N = map(int, input().split())
c = 0
e = 0
f = 0
for i in range(1,N + 1):
	if B > N:
		f = (math.floor(A * N / B)) - (A * math.floor(N / B))
		break
	elif B % i == 0:
		c = i
		break
d=range(c-1,N,B)
for i in d:
	if B > N:
		break
	e = (math.floor(A * i / B))-(A * math.floor(i / B))
	if e>f:
		f=e
print(f)

Submission status: Wrong Answer

Solution code:
import math

a, b, n = map(int, input().split())
x = n
ans = math.floor(a*x/b)-math.floor(x/b)*a
for i in range (a):
    x -= 1
    ans2 = math.floor(a*x/b)-math.floor(x/b)*a
    if ans < ans2:
      ans = ans2
print(ans)

Submission status: Wrong Answer

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

max_num = -1
tmp = 0
for x in range(n+1):
  tmp = int(x / b)
  if max_num > tmp:
    max_num = x - 1
    break

if (max_num == -1):
  max_num = n
  
print(int(a * max_num / b // 1 - a * (max_num / b // 1)))

Submission status: Wrong Answer

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

if a%b == 0:
    if b-1 <= n:
        print(b-1)
    else:
        print(n)
else:
    maxT = 0
    i = 0
    while i <= 100000 and i <= n:
        t = math.floor(a*i/b)-a*math.floor(i/b)
        if t > maxT:
            maxT = t
        i+=1
    wild = max(n//b, (n-1)//b)
    print(max(maxT, wild))

Submission status: Wrong Answer

Solution code:
import math
a,b,n = map(int,input().split())
ans = 0
al = []
    
for i in range(n,-1,-1):
    t = ((a*i)//b)
    t2 = (a*(i//b))
    ans = t-t2
    al.append(ans)
    if len(al) > 2:
        if al[-1] <= al[-3]:
            break
if max(al) < 0:
    print(0)
else:
    print(max(al))

Submission status: Wrong Answer

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

ans = [int((A*(i+(B-1)))/B) - (A*i) for i in range(N+1) if i % B == 0]
ans.append(0)

print(max(ans))

Submission status: Wrong Answer

Solution code:
import math
a,b,n=map(int,input().split())
if b>n:
    print(math.floor(a/b*n))
elif b<n:
    print(math.floor(a/b*1))
else:
    print(math.floor(a/b*(n/2)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
a,b,n = MI()
if n >= b:
  print(a-1)
else:
  print(math.floor(a*n/b)-a*math.floor(n/b))