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: Runtime Error

Solution code:
import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    #     # ans=int(A*x/B)-A*int(x/B)
    #     min,_=math.modf(x/B)
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    max=0
    max_x=0
    reg=[0]*B+1

    for x in range(N+1):
        rem = x%B
        if reg[rem]==1:
            break
        else:
            reg[rem]=1
        if rem > max:
            max=rem
            max_x=x

    # min,_=math.modf(max_x/B)

    print(int(A*max_x/B)-A*int(max_x/B))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a,b,n = map(int,input().split())
ans = 0
for k in range(1,min(b,n+1)):
    ans = max(int(a*k/b) - a*int(k/b),ans)
    if ans == a:
        print(ans)
        break
if ans == a:
    ans = ans
else:
    for k in range(1,n//(b-1)+1):
        ans = max(int(a*(k*b-1)/b) - a*int((k*b-1)/b),ans)
        if ans == a:
            print(ans)
            break
if ans != a:
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    #     # ans=int(A*x/B)-A*int(x/B)
    #     min,_=math.modf(x/B)
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    max=0
    max_x=0
    reg=[0]*B

    for x in range(N+1):
        rem = x%B
        if reg[rem]==1:
            break
        else:
            reg[rem]=1
        if rem > max:
            max=rem
            max_x=x

    # min,_=math.modf(max_x/B)

    print(int(A*max_x/B)-A*int(max_x/B))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import random
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

import math
A, B, N = MII_split()

def f(x):
    """最小値を求めたい関数"""
    return math.floor(A * x / B) - A * math.floor(x / B)

# def numerical_diff(f, x):
#     """中央差分を元に数値微分する関数"""
#     h = 1e-4
#     return (f(x + h) - f(x - h)) / (2 * h)
#
# def gradient_descent(f, initial, learning_rate=1, steps=10):
#     """一階導関数から勾配法で最小値を求める関数"""
#     # 現在地を示すカーソル
#     x = initial
#
#     # 所定の回数を繰り返す
#     for _ in range(steps):
#         # 現在地の勾配 (どちらにどれだけ進むべきか) を得る
#         grad = numerical_diff(f, x)
#         # 勾配を元にして現在地を移動する
#         x -= learning_rate * grad
#
#     # 最終的な位置を返す
#     return f(x)

ma = 0
for _ in range(10 ** 6*1.5):
    ini = random.randrange(N + 1)
    # tmp = gradient_descent(f, ini)
    tmp = f(ini)
    if ma < tmp:
        ma = tmp

print(ma)

Submission status: Runtime Error

Solution code:
import math
A,B,N=map(int,input().split())
max_ans=0
for X in reversed(range(N)):
    if ans>= max_ans:
        ans=math.floor(A*x/B)-A*math.floor(x/B)
        max_ans=ans
print(ans)

Submission status: Runtime Error

Solution code:
a,b,n = map(int, input().split())
M = [0]*b
for x in range(0,b):
    M[x] = int(a*x/b) - a*int(x/b)

print(max(M))

Submission status: Runtime Error

Solution code:
import numpy as np

A, B, N = map(int, input().split()) # 2以上の整数入

ApB = A / B

ans = 0
for x in np.array(range(N)) + 1:
	t = int(ApB * x) - A * int(x/B)
	if (t > ans):
		ans = t

print(ans)

Submission status: Runtime Error

Solution code:
import math
import copy
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

A,B,N = [int(hoge) for hoge in input().split()]
G = math.gcd(A,B)
Old_A = copy.deepcopy(A)
A = A//G
invA = mod_inv(A,B)
if A >= B: 
    x = N
    print((Old_A*x)//B - Old_A * (x//B))

else:   
    InvList = []
    for i in range(A):
        #Ax=i(modB)なので、x = i*(inv_A) mod B
        if i:
            amari = (i * invA)%B #候補のx mod B
        else:amari = 0# Ax mod B=0 のとき、x mod B = 0
        x = N - N%B + amari
        if x > N :x-=B
        axx = (amari,x,(Old_A*x)//B - Old_A * (x//B))
        if x < 0:continue
        InvList.append(axx)
    InvList.sort(key = lambda x:x[2],reverse=True)
    print(InvList[0][2])

Submission status: Runtime Error

Solution code:
a, b, n = map(int, input().split())
if n < b:
    ans = a*n//b
else:
    ans = max(ans, (a*(b*2-1))//b - a)
    li = [1, (1+(n//b))//2, -(-(1+(n//b))//2)]
    for i in li:
        check = (a*(b*(i+1)-1))//b - a*i
        ans = max(ans, check)
    ans = max(ans, (a*n)//b)-a*(n//b)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A,B,N=map(int,input().split())
ans=[0]*N
for x in range(0,N+1):
    a=int((A*x)/B)
    b=A*int(x/B)
    ans[x-1]+=a-b
print(max(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

#ans = 0
#for x in range(1, N+1):
#    total = ((A * x) // B) - A * (x // B)
#    print(x, total)
#print(ans)
print(((A * x) // B) - A * (x // B))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import copy
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

A,B,N = [int(hoge) for hoge in input().split()]
G = math.gcd(A,B)
Old_A = copy.deepcopy(A)
A = A//G
invA = mod_inv(A,B)
if A >= B: 
    x = N11 10 9
    print((Old_A*x)//B - Old_A * (x//B))

else:   
    InvList = []
    for i in range(A):
        #Ax=i(modB)なので、x = i*(inv_A) mod B
        if i:
            amari = (i * invA)%B #候補のx mod B
        else:amari = 0# Ax mod B=0 のとき、x mod B = 0
        x = N - N%B + amari
        if x > N :x-=B
        axx = (amari,x,(Old_A*x)//B - Old_A * (x//B))
        if x < 0:continue
        InvList.append(axx)
    InvList.sort(key = lambda x:x[2],reverse=True)
    print(InvList[0][2])

Submission status: Runtime Error

Solution code:
import math


nums = [int(e) for e in input().split()]

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

max_score = -1
score = -1

while True:
    score = math.floor(a*x/b) - a* math.floor(x/b)
    if max_score < score:
        max_score = score
    elif x > n:
        break

print(max_score)

Submission status: Runtime Error

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

x = list()
for i in range(n):
  y = int(a*(i+1)/b) - a*int((i+1)/b)
  x.insert(bisect.bisect_left(x,y))

print(x[-1])

Submission status: Runtime Error

Solution code:
num = input()

import math

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

anslist = []
for x in range(N):
  ans = math.floor(A*x/B) - A * math.floor(x/B)
  anslist.append(ans)
  
print(max(anslist))

Submission status: Runtime Error

Solution code:
arr = input().split(" ")
a, b, n = int(arr[0]), int(arr[1]), int(arr[2])
if b<=n:
  k = a
else:
  k = (a*((n-1))//b
print(k)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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

l = np.zeros(N+1)

for i in range(1,N+1):
    l[i] = math.floor((A*i)/B) - A * math.floor(i/B)

print(int(np.max(l)))

Submission status: Runtime Error

Solution code:
from math import floor
import numpy as np

a, b, n = map(int, input().split())
# a, b, n = 4628, 3261783, 3421421

res_arr = np.vectorize(lambda x: floor(a*x / b) - a * floor(x / b))(np.arange(1, n+1))
# np.nanmax(res_arr)
print(np.nanmax(res_arr))

Submission status: Runtime Error

Solution code:
a,b,n = map(int,input().split())
ans = 0
for k in range(1,n+1):
    ans = max(int(a*k/b) - a*int(k/b),ans)
    if ans == a:
        print(ans)
        break
if ans == a:
    ans = ans
else:
    for k in range(1,n//(b-1)+1):
        ans = max(int(a*(k*b-1)/b) - a*int((k*b-1)/b),ans)
        if ans == a:
            print(ans)
            break
if ans != a:
    print(ans)

Submission status: Runtime Error

Solution code:
import math

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

a = int((A+B)/2)
b = int((A+N)/2)
c = int((B+N)/2)
d = int(x/B)
e = int(A*x/B)

max=0
x_max=-1

for x in range(A-k,A+k):
	if x>0 and x<=N:
		tmp = math.floor(A*x/B)-A*math.floor(x/B)
		if max<=tmp:
			max=tmp
			x_max=x

for x in range(B-k,B+k):
	if x>0 and x<=N:
		tmp = math.floor(A*x/B)-A*math.floor(x/B)
		if max<=tmp:
			max=tmp
			x_max=x

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

for x in range(a-k,a+k):
	if x>0 and x<=N:
		tmp = math.floor(A*x/B)-A*math.floor(x/B)
		if max<=tmp:
			max=tmp
			x_max=x

for x in range(b-k,b+k):
	if x>0 and x<=N:
		tmp = math.floor(A*x/B)-A*math.floor(x/B)
		if max<=tmp:
			max=tmp
			x_max=x

for x in range(c-k,c+k):
	if x>0 and x<=N:
		tmp = math.floor(A*x/B)-A*math.floor(x/B)
		if max<=tmp:
			max=tmp
			x_max=x

for x in range(d-k,d+k):
	if x>0 and x<=N:
		tmp = math.floor(A*x/B)-A*math.floor(x/B)
		if max<=tmp:
			max=tmp
			x_max=x

for x in range(e-k,e+k):
	if x>0 and x<=N:
		tmp = math.floor(A*x/B)-A*math.floor(x/B)
		if max<=tmp:
			max=tmp
			x_max=x				

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



for x in range(1,k):
	if x>0 and x<=N:
		tmp = math.floor(A*x/B)-A*math.floor(x/B)
		if max<=tmp:
			max=tmp
			x_max=x			
print(max)

Submission status: Runtime Error

Solution code:
import math
def func(x,a,b):
    return math.floor((a*x)/b)-a*math.floor(x/b)
a,b,n=map(int,input().split())
mx=0
st=b-1
i=0
j=n 
while(i<=j):
    mid=(i+j)/2
    xx=func(mid,a,b)
    yy=func(mid-1,a,b)
    if (xx>mx):
        mx=xx
    if xx>yy:
        i=mid+1
    elif xx<yy:
        j=mid-1
    else:
        for mm in range(mid-2,0,-1):
            ch=func(mm,a,b)
            if xx>ch :
                i=mid+1 
            elif xx<ch :
                if(ch>mx):
                    mx=ch
                j=mid-1
    
print(mx)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

A, B, N = map(int, input().split()) # 2以上の整数入力

ApB = A / B

ans = 0
for x in np.array(range(N)) + 1:
	t = math.floor(ApB * x) - A * math.floor(x/B)
	if (t > ans):
		ans = t

print(ans)

Submission status: Runtime Error

Solution code:
import numpy
str = input()
lst = str.split()
a = int(lst[0])
b = int(lst[1])
c = int(lst[2])
if b > c:
    print(int(a*c/b)-int(c/b)*a)
else:
    d = int(c/b)
    lst = np.zeros(d)
    for i in range(d):
        k = b*(i+1)-1
        lst[i] = int(a*k/b)-int(k/b)*a
    print(np.max(lst))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

x = math.floor(a*n/b)-( a*math.floor(n/b))
y = math.floor(a*b/b)-( a*math.floor(b/b))
z = math.floor(a*(b-1)/b)-( a*math.floor((b-1)/b))

if b == 1:
    print(0)
elif n < b:
    print(x)
else:
    print(z)

Submission status: Runtime Error

Solution code:
import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    #     # ans=int(A*x/B)-A*int(x/B)
    #     min,_=math.modf(x/B)
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    max=0
    max_x=0
    reg=[0]*10

    for x in range(N+1):
        rem = x%B
        if reg[rem]==1:
            break
        else:
            reg[rem]=1
        if rem > max:
            max=rem
            max_x=x

    # min,_=math.modf(max_x/B)

    print(int(A*max_x/B)-A*int(max_x/B))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
import numpy as np

A, B, N = map(int, input().split()) # 2以上の整数入力

ApB = A / B

ans = 0
print(np.array(range(N)) + 1)
for x in np.array(range(N)) + 1:
	t = math.floor(ApB * x) - A * math.floor(x/B)
	if (t > ans):
		ans = t

print(ans)

Submission status: Runtime Error

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

max = -1

if n < b:
    x = n
elif b < n:
    x = b-1

new = math.floor(a*x/b) - a * math.floor(x/b)

print(new)

Submission status: Runtime Error

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

    def calc(x):
        return int((a * x) / b) - (a * int(x / b))

    if calc(1) < calc(n // 2):
        return max([calc(i) for i in range(n // 2, n + 1)])
    else:
        return max([calc(i) for i in range(1, n // 2 + 1)])


print(m())

Submission status: Runtime Error

Solution code:
li=[]
a,b,n=map(int,input().split())
for x in range(1,n+1):
    if x%b!=0:
        li.append((a*x)//b-a*(x//b))
print(max(li))

Submission status: Runtime Error

Solution code:
A,B,N = map(int,input().split())
S =[]
if B>N:
    print(int(A*N/B)-A*(int(N/B)))
else:
    print(int(A*N/(B-1))-A*(int((B-1)/B)))

Submission status: Runtime Error

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

res = floor(a/b) - a * floor(1/b)

for i in range(2,n+1):
    res_aftr = floor(a*i/b) - a * floor(i/b)
    if res_aftr > res:
        res = res_aftr

print(res_aftr)

Submission status: Runtime Error

Solution code:
import math

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

max_ans = math.floor(a*n/b) - a*math.floor(n/b)
for x in range(n, 1, -1):
    ans = math.floor(a*x/b) - a*math.floor(x/b)
    if max_ans <= ans:
        print(ans)
        break
else:
    print(ans)

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input().split())
ans=[0]*b
if c>b-2:
    for i in range(b):
        d=(i+1)*b-1
        ans[i]=int((a*d)/b)-d*(int(d/b))
        print(ans[i])
        if c<=d:
            break
        if i==1000000:
            break
else :
    ans[0]=int((a*c)/b)-b*(int(c/b))
print(max(ans))

Submission status: Runtime Error

Solution code:
solved_flag = False
if B==1:
    ans = 0
    solved_flag = True
else:
    if B <= N:
        x = B-1
    else:
        x = N

if not solved_flag:
    ans = math.floor(A*x/B) - A*math.floor(x/B)
print(ans)

Submission status: Runtime Error

Solution code:
for i in range(N):
    
    _n = int(A*i/B) - A*int(i/B)
    if n < _n:
        n = _n
    if n >= _n
        break

print(n)

Submission status: Runtime Error

Solution code:
import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    #     # ans=int(A*x/B)-A*int(x/B)
    #     min,_=math.modf(x/B)
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    max=0
    max_x=0
    reg=[0]*10

    for x in range(N+1):
        rem = x%B
        if reg[rem]==1:
            break
        else:
            reg[rem]=1
        if rem > max:
            rem = max
            max_x=x

    # min,_=math.modf(max_x/B)

    print(int(A*max_x/B)-A*int(max_x/B))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

mx = -1
count = 0
for x in reversed(range(1, N+1)):
  temp = ((A*x) // B) - A*(x//B)
  mx = max(mx, temp)
  count +=1
  if count == 340000000:
    break
if N >= 100000000000
  print(mx-1)
else: 
  print(mx)

Submission status: Runtime Error

Solution code:
mport math

A, B, N = map(int, input().split())
res = math.floor(((A * 1) / B)) - A * math.floor((1 / B))

for i in range(1, N + 1, 2):
    a = math.floor(((A * i) / B)) - A * math.floor((i / B))
    if res < a: res = a
print(res)

Submission status: Runtime Error

Solution code:
import math
a,b,c = map(int,input().split())
ans = [0]*c
for x in range(c, 0, int(-1)):
    ans[x-1] = math.floor(a*x/b) -  a* math.floor(x/b)
print(max(ans))

Submission status: Runtime Error

Solution code:
import math

A, B, N = map(int, input().split())
l = [0]*N
for i in range(N):
  l[i] = (math.floor((A*(i+1))/B)) - A*(math.floor((i+1)/B))
  
print(max(l))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
A, B, N = MAP()

x = N
ans = (A * x//B) - A * (x // B)

memo = [0] * (B+1)
for x in range(1, B+1):
    memo[x] = (A * (x)//B) - A * ((x)  // B)
# print(memo[N-1])
# print(memo)
# print(N)

# exit()
if N >= B:
    ans = memo[-2]
else:
    ans = memo[N]
print(ans)

Submission status: Runtime Error

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

result = []
if n < b:
    print(math.floor(a * n / b) - a * math.floor(n / b))

else:
    i = n
    while i == 0:
        result.append(math.floor(a * i / b) - a * math.floor(i / b))
        i = i - 1
    print(max(result))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import copy
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

A,B,N = [int(hoge) for hoge in input().split()]
G = math.gcd(A,B)
Old_A = copy.deepcopy(A)
A = A//G
invA = mod_inv(A,B)
if A >= B:
    print(N)

else:   
    InvList = []
    for i in range(A):
        #Ax=i(modB)なので、x = i*(inv_A) mod B
        if i:
            amari = (i * invA)%B #候補のx mod B
        else:amari = 0
        x = N - N%B + amari
        if x > N :x-=B
        axx = (amari,x,Old_A*x - (Old_A*x)%B)
        if x < 0:continue
        InvList.append(axx)
    InvList.sort(key = lambda x:x[2],reverse=True)
    print(InvList[0][2]//B)

Submission status: Runtime Error

Solution code:


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

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

print(ans)

Submission status: Runtime Error

Solution code:
a, b, n = map(int, input().split())
ans = 0
for i in range(int(b/a), n+1):
  if ans < int(a*i/b)-a*int(i/b);
    ans = ans, int(a*i/b)-a*int(i/b)
  else:
    break
print(ans)

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
A = a[0]
B = a[1]
N = a[2]
ans = [0]*(N+1)
for i in range(N+1):
  ans[i] = int(A*i/B)-A*int(i/B)
print(max(ans))

Submission status: Runtime Error

Solution code:
import sys
import os
import math

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    #     # ans=int(A*x/B)-A*int(x/B)
    #     min,_=math.modf(x/B)
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    max=0
    max_x=0
    reg=[0]*10

    for x in range(N+1):
        rem = x%B
        if reg[rem]==1:
            break
        else:
            reg[rem]=1
        if rem > max:
            rem = max
            max_x=x

    min,_=math.modf(max_x/B)

    print(int(min*A))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

if b-1 > n:
    x = n
else:
    x = (n // (b-1)) * (b-1)
answer = max(0, (a*x)//b - a*(x//b))

print(answer)

Submission status: Runtime Error

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

ans = -1
#for x in range(n-int(n**(1/2))-1,n+1):
for x in range(1,n+1,n-1):
    abc = ((a*x)//b)-(a*(x//b))
    if(ans < abc):
        ans = abc

print(ans)

Submission status: Runtime Error

Solution code:
from math import floor

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

x = None
if N < B:
    x = N

answer = floor(A * x / B) - A * floor(x / B)

print(answer)

Submission status: Runtime Error

Solution code:
import math

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

m = 0
n = 1

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

while n<N:
  c = B*(math.floor((n+1)/B)+1)-1
  n = min(N, c)
  m = max(cal(n), m)
  if (A*x)%B == 0:
    break
  
print(m)

Submission status: Runtime Error

Solution code:
import numpy as np
def fun(x):
    return np.floor(A*x/B)-A*np.floor(x/B)

A, B, N = map(int,input().split())
if B<N:
    x = np.arange(0, B, 1)
else:
    x = np.arange(0, N+1, 1)

print(int(max(fun(x))))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import numpy as np

A, B, N = map(int, input().split()) # 2以上の整数入力

ApB = A / B

ans = 0
for x in np.array(range(N)) + 1:
	t = math.floor(ApB * x) - A * math.floor(x/B)
	if (t > ans):
		ans = t
	else:
		print(ans)
		exit()

print(ans)

Submission status: Runtime Error

Solution code:
import math

A, B, N = map(int, input().split())
l = [0]*N
for i in range(N):
  l[i] = (math.floor(A*(i+1)/B)) - A*(math.floor((i+1)/B))
  
print(max(l))

Submission status: Runtime Error

Solution code:
import math
a, b, n =map(int,input().split())
x = 0
ans = [0]*(n+1)
pre = math.floor(a*x/b)
aft = a*(math.floor(x/b))
for x in range(n+1) :
  pre = math.floor(a*x/b)
  aft = a*(math.floor(x/b))
  ans[x] = pre - aft
print(max(ans))

Submission status: Runtime Error

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

if (B > N+1):
  x = N
  print((A*x)//B-A*(x//B))
else:
  x = N-N%(B-1)
  print((A*x)//B-A*(x//B))

Submission status: Runtime Error

Solution code:
11 10 9

Submission status: Runtime Error

Solution code:
import math
b = list(map(int,input().split()))
ans=0
check=0
i=0
A=0
B=0
C=b[1]
max = b[2]//b[1]
if max==0 or max==1:
    for i in range(b[2]+1):
        if b[2]-i <=0:
            break
        check = math.floor((b[0]*(b[2]-i))/b[1]) - b[0]*math.floor((b[2]-i)/b[1])
        if check > ans:
            ans=check

else:
    for i in range(1,max+1):
        A=b[1]-1
        
        check = math.floor((b[0]*A)/C) - b[0]*math.floor(A/C)
        if check > ans:
            ans=check
        b[1]+=b[1]
print(ans)

Submission status: Runtime Error

Solution code:
import math
a,b,n = map(int,input().split())
if b != 1:
    x = min(n, b-1)
    while x <= n:
        Max = max(math.floor(a*x/b) - a*math.floor(x/b),Max)
        x += b
else:
    Max = 0
print(Max)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import math
import numpy as np
import time
input = sys.stdin.readline

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

Submission status: Runtime Error

Solution code:
import math
line = input()
a, b, n = line.split(" ")
a, b, n = int(a), int(b), int(n)
ans = 0
ans_list = []
temp = int(n/10)
print(temp)

for i in range(n,n-temp,-1):
    ans = math.floor((a*i)/b) - math.floor(i/b)
    ans_list.append(ans)
print(max(ans_list))

Submission status: Runtime Error

Solution code:
a,b,n = map(int, input().split())
M = [0]*(n+1)
for x in range(0,n+1):
    M[x] = int(int(a*x/b) - a*int(x/b))

print(max(M))

Submission status: Runtime Error

Solution code:
def main():
    import sys
    import heapq
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    A,B,N=map(int,input().split())
    Z=[0]*(N+1)
    for x in range(N+1):
        Y=int(A*x/B)-A*int(x/B)
        Z[x]=-1*Y
    heapq.heapify(Z)
    result=-1*heapq.heappop(Z)
    print(result)    

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

    for x in range(n, 0, -1):
        fx = math.floor(a * x / b) - math.floor(x / b) * a
        #print(fx)
        if ans < fx:
            ans = fx
        if ans > fx + 10 ** 3:
            #exit()
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math


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

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

    if calc(1) < calc(n // 2):
        return max([calc(i) for i in range(n // 2, n + 1)])
    else:
        return max([calc(i) for i in range(1, n // 2 + 1)])


print(m())

Submission status: Runtime Error

Solution code:
A,B,N = map(int,input().split())
x = math.gcd(N,B)
K = math.floor(N/B)
if K == 0:
    print(math.floor(A*N/B)-A*math.floor(N/B))
else:
    alpha = B*(K+1)-1
    if alpha > N:
        alpha = N
    print(math.floor(alpha/B)-A*math.floor(alpha/B))

Submission status: Runtime Error

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

if (B > N+1):
  x = N
  print(math.floor(A*x/B)-A*math.floor(x/B))
else:
  x = N-N%(B-1)
  print(math.floor(A*x/B)-A*math.floor(x/B))

Submission status: Runtime Error

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)


for i in range(1,N) :
    if i >= 2 and fl(i) < fl(i-1) :
        An = fl(i-1)
        break
    else:
        An = fl(N)

print(str(An))

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
import math
a,b,n=map(int,input().split())
for x in range(n+1):
    f=math.floor(a*x/b)-a*math.floor(x/b)
    m.append(f)
print(max(m))

Submission status: Runtime Error

Solution code:
import math
b = list(map(int,input().split()))
ans=0
check=0
i=0
A=0
B=0
C=b[1]
max = b[2]//b[1]
if max==0 or max==1:
    for i in range(b[2]+1):
        if b[2]-i <=0:
            break
        check = math.floor((b[0]*(b[2]-i))/b[1]) - b[0]*math.floor((b[2]-i)/b[1])
        if check > ans:
            ans=check

else:
    for i in range(1,max+1):
        A=b[1]-1
        B=b[1]+1
        check = math.floor((b[0]*A)/C) - b[0]*math.floor(A/C)
        if check > ans:
            ans=check
        check = math.floor((b[0]*B)/C) - b[0]*math.floor(B/C)
        if check > ans:
            ans=check
        B[1]+=b[1]
print(ans)

Submission status: Runtime Error

Solution code:
a,b,n = map(int, input().split())
M = [0]*(n+1)
for x in range(0,n+1):
    M[x] = int(a*x/b) - a*int(x/b)

print(max(M))

Submission status: Runtime Error

Solution code:


def floor(t):
    return int(t)


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

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

    ans = 0

    low = 1
    if N % 2 == 0:
        high = N
    else:
        high = N + 1

    while abs(low - high) != 1:
        mid = (high + low) // 2
        tmp = fs(A, B, mid)
        if tmp > ans:
            ans = tmp
            low = mid
        else:
            high = mid

    print(tmp)


    return 0

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

if N < B:
    if N % B == 0:
        x = N-1
    else:
        x = N
        ans = math.modf((N/B))[0]*A

else:
    if N % B == 0:
        x = (N-1)%B
    else:
        x = N%B

ans = math.modf((x/B))[0]*A
print(int(ans))