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/env python3
# -*- coding: utf-8 -*-

import math as mt

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

    maxn = 0
    
    if N > B:
        nn = N // B
        for x in range(B*nn-1, 1, -B):
            temp = mt.floor(A*x/B) - A*mt.floor(x/B)
            if temp >= maxn:
                maxn = temp
            else:
                break
    elif N == B:
        maxn = mt.floor(A*(N-1)/B) - A*mt.floor((N-1)/B)
    else:
        maxn = mt.floor(A*N/B) - A*mt.floor(N/B)
    
    print(maxn)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

y = min(b, n)
if b != n:
    print((a*y)//b)
else:
    if b <= y:
        print((a*y)//b + a)
    else:
        o = (a*y)//b + a*(y//b)
        p = (a*n)//b + a*(n//b)
        print(max(o, p))

Submission status: Wrong Answer

Solution code:
#二分法による非線型方程式の解法プログラム
import numpy as np  #数値計算用モジュール

#解きたい方程式
def func_f(A,B,x):
    return -(int(A*x/B)-A*int(x/B))


#二分法（方程式の関数項、探索区間の左端、探索区間の右端、誤差範囲、最大反復回数）
def bisection(func_f, x_min, x_max, A, B, error=0.1, max_loop=1000):
    #初期値を表示
    num_calc = 0  #計算回数
    #print("{:3d}:  {:.15f} <= x <= {:.15f}".format(num_calc, x_min, x_max))
    
    #中間値の定理の条件を満たすか調べる
    if(0.0 < func_f(A,B,x_min)*func_f(A,B,x_max)):
        #print("error: Section definition is invalid (0.0 < func_f(x_min)*func_f(x_max)).")
        quit()

    #ずっと繰り返す
    while(True):
        #新たな中間値の計算
        x_mid = int((x_max +x_min)/2.0)
        
        x_mid_max = int((x_max +x_mid)/2.0)
        x_mid_mim = int((x_min +x_mid)/2.0)
        
        #探索区間を更新
        if func_f(A,B,x_max) <= func_f(A,B,x_mid):
            x_mid = x_max
            break
        elif func_f(A,B,x_min) <= func_f(A,B,x_mid):
            x_mid = x_min
            break
        elif func_f(A,B,x_mid_max) < func_f(A,B,x_mid_mim):  #中間と右端の値が同じの時
            x_max = x_mid  #右端を更新
        else:  #中間と左端の値が同じの時
            x_min = x_mid  #左端を更新
        
        #結果を表示
        num_calc += 1  #計算回数を数える
        print("{:3d}:  {:.15f} <= x <= {:.15f}".format(num_calc, x_min, x_max))
        
        #「誤差範囲が一定値以下」または「計算回数が一定値以上」ならば終了
        if((x_max-x_min <= error) or max_loop <= num_calc):
            break

    #最終的に得られた解
    #print("x = {:.15f}".format(x_mid))

    return x_mid


#メイン実行部
if (__name__ == '__main__'):
    A,B,N=(int(x) for x in input().split())
    #二分法で非線型方程式の解を計算
    solution = bisection(func_f, 0, N, A, B)
    print(-func_f(A,B,solution))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b, x = map(int, input().split())
print(a * (b - 1) // b)

Submission status: Wrong Answer

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

from pprint import pprint as pp
from pprint import pformat as pf

import math

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

if __name__ == '__main__':
    a, b, n = map(int, input().split())
    if b > n:
        x = n
    else:
        k = n // b
        x = (b * k - 1)
    print(calc(a, b, x))

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-1, N)
max = int(A*max_of_x/B)

x=B*2-1
score = int(A*x/B) - A*int(x/B)
if score>max:
    max = score
print(max)

Submission status: Wrong Answer

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

k = gcd(A, B)

As = A // k
Bs = B // k

if As == 1:
    print(0)

if B-1 <= N:
    m, n = B - 1, Bs - 1
elif Bs - 1 <= N:
    m, n = Bs - 1, Bs - 1
else:
    m, n = N, N
print(round(floor(As * n / Bs) - As * floor(m / Bs)))

Submission status: Wrong Answer

Solution code:
import math

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

temp = -1 * float('inf')
temp2 = -1 * float('inf')



if A > N or B > N:
    temp = math.floor(A*N/B) - A*math.floor(N/B)
if A > B  and B < N:
    temp = math.floor(A*(B-1)/B) - A*math.floor((B-1)/B)
elif A < B and B < N:
    temp = math.floor(A*(B-1)/B) - A*math.floor((B-1)/B)
else:
    x = A - 1
    while x <= N - A:
        if temp <= math.floor(A*x/B) - A*math.floor(x/B):
            temp = math.floor(A*x/B) - A*math.floor(x/B)
            x += A
    if temp <= math.floor(A*N/B) - A*math.floor(N/B):
        temp = math.floor(A*N/B) - A*math.floor(N/B)

print(temp)

Submission status: Wrong Answer

Solution code:
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7


a, b, n = multi_int_input()

lb = min(b, n)
if b == n:
    lb = n-1
ans1 = ((lb*a)//b)- a*(lb//b)
ans2 = ((n*a)//b) - a*(n//b)

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import fractions
import copy
import bisect
import math
import numpy as np

#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


N=3
M=3
i=0
j=0
k=0
n=3
r=1
a=[0]*5
b=[]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
pre=0

"1行1つの整数を入力を取得し、整数と取得する"
A,B,N=map(int, input().split(" "))
syo=len(str(N))
if syo <10**4:
 for i in range(N+1):
    k=(A*(i//B))-A*(i//B)
    if pre > k :
        print(pre)
        sys.exit()
    pre=k
    b.append(k)
    k=0
for i in range(N+1):
        k=(A*(i+10**(syo-1))//B)-A*((i+10**(syo-1))//B)
        #print(pre,k)
        if pre > k:
            print(pre)
            sys.exit()
        pre=k
        b.append(k)
        k=0

print(max(b))
#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation

'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''





########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

Submission status: Wrong Answer

Solution code:
a,b,n=map(int,input().split())
m=min(n,b)
tmp=(a*m//b)-(((m-1)//b)*a)    
print(tmp)

Submission status: Wrong Answer

Solution code:
from math import floor, gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

def main():
    A, B, N = list(map(int, input().split(' ')))
    
    tmp = 0
    
    mods = []
    # print([A * x % B for x in range(B)])
    for x in range(N):
        m = A * x % B
        if m >= 1:
            mods.append(m)
        else:
            if A < B:
                mods.append(1000000000000000000000)
            else:
                mods.append(0)
        
    
    print(mods)
    if A < B:
        index = mods.index(min(mods))
    else:
        index = mods.index(max(mods))
    print(index+1)

    # for x in range(1, N+1):
    #     out = floor(A * x / B) - floor(x / B)
    #     tmp = max(tmp, out)
    # print(tmp)
    
    
main()

Submission status: Wrong Answer

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

def g(t):
    return int(A*t/B)-A*int(t/B)

Num=[g(i) for i in range(N)] 

print(max(Num))

Submission status: Wrong Answer

Solution code:
import math
a,b,c = map(int,input().split())
res = [] 
i=0

ress = math.floor((c*a)/b) - a * math.floor(c/b)
res.append(ress)
i=i+1
print(max(res))

Submission status: Wrong Answer

Solution code:
import math

def siki(A, B, X):
	return math.floor((A*X)/B) - A*math.floor(X/B)

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

if N < B:
	k = N
else:
	k = B

right = N
left = 0
for i in range(1, k+1):

	mid = left + math.floor(right - left) / 2
	print(mid)
	print(siki(A,B,mid))
	if max_value > siki(A,B,mid):
		right = mid
	else :
		left = mid

	if max_value < siki(A,B,mid):
		max_value = siki(A,B,mid)
	print(max_value)


print(max_value)

Submission status: Wrong Answer

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

if a == b and b == n:
    print(a-1)
else:
    if a <= b:
        if a >= n:
            #n_tmp = n % a
            #print(n_tmp)
            #if n_tmp == 0:
            n_tmp = n
            ans = int(a*n_tmp/b) - a*int(n_tmp/b)
            #print(ans)
            #print('####')

            ##for x in range(n+1):
             #   ans = int(a*x/b) - a*int(x/b)
             #   print(ans)

        else:
            ans = a-1
            print(ans)

            ##for x in range(n + 1):
             #   ans = int(a*x/b) - a*int(x/b)
             #   print(ans)


    else:
        if a >= n:
            ans_max = 0
            n_tmp = n
            for x in range(n_tmp+1):
                ans = int(a*x/b) - a*int(x/b)
                #print(ans)
                if ans_max < ans:
                    ans_max = ans

            print(ans_max)

        else:
            ans_max = 0
            n_tmp = a
            for x in range(n_tmp + 1):
                ans = int(a * x / b) - a * int(x / b)
                #print(ans)
                if ans_max < ans:
                    ans_max = ans

            #print('max##########################')
            print(ans_max)

            #print('#########################')
            #for x in range(n + 1):
            #    ans = int(a * x / b) - a * int(x / b)
            #    print(ans)
                #if ans_max < ans:
                #    ans_max = ans

            #print(ans_max)

Submission status: Wrong Answer

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

if((((a*(1))//b) - (a *((1)//b)))) == 1:
    g = min(a,b,n)
    if g > 9:
        ans += g
        print(g+(g//10)+1+(g//100)+(g//1000)+(g//10000)+(g//100000)+(g//1000000)+(g//10000000)+(g//100000000)+(g//1000000000)+(g//10000000000)+(g//100000000000))
    else:
        print(g)
    exit()

if(a > n and b > n):
    print((((a*(n-1))//b) - (a *((n-1)//b))))
    exit()
else:
    if(a > n):
        ans = max((((a*(b-1))//b) - (a *((b-1)//b))),(((a*(n-1))//b) - (a *((n-1)//b))))
    elif(b > n):
        ans = max((((a*(a-1))//b) - (a *((a-1)//b))),(((a*(n-1))//b) - (a *((n-1)//b))))
    else:
        ans = max((((a*(a-1))//b) - (a *((a-1)//b))),(((a*(b-1))//b) - (a *((b-1)//b))))
print(ans)

Submission status: Wrong Answer

Solution code:
def floor(A,B,x):
    return int(A*x/B)-A*int(x/B)

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

ans =max(floor(A,B,N),floor(A,B,max(0,B*(N//B)-1)),floor(A,B,N-A*N%B))


print(ans)

Submission status: Wrong Answer

Solution code:
#二分法による非線型方程式の解法プログラム
import numpy as np  #数値計算用モジュール

#解きたい方程式
def func_f(A,B,x):
    return -(int(A*x/B)-A*int(x/B))


#二分法（方程式の関数項、探索区間の左端、探索区間の右端、誤差範囲、最大反復回数）
def bisection(func_f, x_min, x_max, A, B, error=0.1, max_loop=1000):
    #初期値を表示
    num_calc = 0  #計算回数
    #print("{:3d}:  {:.15f} <= x <= {:.15f}".format(num_calc, x_min, x_max))
    
    #中間値の定理の条件を満たすか調べる
    if(0.0 < func_f(A,B,x_min)*func_f(A,B,x_max)):
        #print("error: Section definition is invalid (0.0 < func_f(x_min)*func_f(x_max)).")
        quit()

    #ずっと繰り返す
    while(True):
        #新たな中間値の計算
        x_mid = int((x_max +x_min)/2.0)
        
        x_mid_max = int((x_max +x_mid)/2.0)
        x_mid_mim = int((x_min +x_mid)/2.0)
        
        #探索区間を更新
        if func_f(A,B,x_max) < func_f(A,B,x_mid):
            x_mid = x_max
            break
        elif func_f(A,B,x_min) < func_f(A,B,x_mid):
            x_mid = x_min
            break
        elif func_f(A,B,x_mid_max) < func_f(A,B,x_mid_mim):  #中間と右端の値が同じの時
            x_max = x_mid  #右端を更新
        else:  #中間と左端の値が同じの時
            x_min = x_mid  #左端を更新
        
        #結果を表示
        num_calc += 1  #計算回数を数える
        print("{:3d}:  {:.15f} <= x <= {:.15f}".format(num_calc, x_min, x_max))
        
        #「誤差範囲が一定値以下」または「計算回数が一定値以上」ならば終了
        if((x_max-x_min <= error) or max_loop <= num_calc):
            break

    #最終的に得られた解
    #print("x = {:.15f}".format(x_mid))

    return x_mid


#メイン実行部
if (__name__ == '__main__'):
    A,B,N=(int(x) for x in input().split())
    #二分法で非線型方程式の解を計算
    solution = bisection(func_f, 0, N, A, B)
    print(-func_f(A,B,solution))

Submission status: Wrong Answer

Solution code:
import math


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

    ans = 0
    div_ab = A/B
    div_1b = 1/B

    for i in range(max(1, N-100000), N + 1):
        ans = max(math.floor(div_ab*i) - A*math.floor(div_1b*i),ans)
    if N > B:
        for j in range(max(int(B)-10000,1), int(B)+1):
            ans = max(math.floor(div_ab * j) - A * math.floor(div_1b * j), ans)

    for k in reversed(range(N-100*B,N+1,B)):
        ans = max(math.floor(div_ab * k) - A * math.floor(div_1b * k), ans)
    for j in range(N-100, N+1):
        ans = max(math.floor(div_ab * j) - A * math.floor(div_1b * j), ans)
    print(int(ans))


if __name__ == '__main__':
    solve()

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
    yd_b = 1

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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

ab = a/b
maxi = 0
st = max(0, n-a-1)
for x in range(st, n+1):
    z = 0
    
    z = math.floor(ab * x) - a * math.floor(x/b)
    if z > maxi:
        maxi = z

for x in range(0, a):
    # z = 0
    if x < b:
        z = math.floor(ab * x)
    else:
        z = math.floor(ab * x) - a * math.floor(x/b)
    if z > maxi:
        maxi = z

print(maxi)

Submission status: Wrong Answer

Solution code:
def resolve():
    import math
    a,b,n  = map(int, input().split())
    maemax=math.floor(a*n/b)
    ushiromax=math.floor(n/b)
    m=math.floor(a/b)
    if m+1>=a:
        if maemax*b%a==0:
          i=int(maemax*b/a)-1
        else:
          i=math.floor(maemax*b/a)-1
        j=ushiromax*b-1
        if j<=i:
          print(maemax-a*ushiromax)
        else:
          print(math.floor(j*a/b)-a*math.floor(j/b))
    else:
        i=math.ceil(b/a)
        j=b
        if j<=i:
          print(0)
        else:
          print(math.floor((i+1)*a/b)-a*math.floor((i+1)/b))
resolve()

Submission status: Wrong Answer

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

answer=0
if N<B:
    answer=int(A*N/B)-A*int(N/B)
else:
    answer=A//(math.gcd(A,B)**2)
print(answer)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
#from fractions import gcd
from math import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

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

def main():
    l = 0
    r = n
    while r-l > 1:
        mid = (r+l) // 2
        if f(mid) > f(l):
            l = mid
        else:
            r = mid
    print(f(l)) if f(l) > f(r) else print(f(r))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import decimal
A, B, N = map(int, input().split())
S =[]

for x in range(0,N):
  c = decimal.Decimal(str(A*x/B))
  C = int(c.quantize(decimal.Decimal('0'), rounding=decimal.ROUND_FLOOR))
  d = decimal.Decimal(str(x/B))
  D = int(d.quantize(decimal.Decimal('0'), rounding=decimal.ROUND_FLOOR))
  D = D * A
  E = C-D
  S.append(E)
  
print(max(S))

Submission status: Wrong Answer

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

y = min(b, n)
if b != n:
    print((a*y)//b)
else:
    if b <= n:
        print((a*y)//b + a)
    else:
        o = (a*y)//b + a*(y//b)
        p = (a*n)//b + a*(n//b)
        print(max(o, p))

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-n%(b/a)+1)//(b/a)>=a*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:
import math
a,b,n = map(int,input().split())
m = 0
x = 1
ax = a*x
while ax/b <0.01:
    x*=10
    ax = a*x
    if x>n:
        x//10
        break
if a-b==1:
    print(n)
elif b-a==1:
    print(n-1)
else:
    for i in range(x,n+1):
        if i==b-1:
            ch = (a*i//b)-a*(i//b)
            print(ch)
            break

Submission status: Wrong Answer

Solution code:
import math
A, B, N = map(int, input().split())
lists = []
for x in range(1, N+1):
    i = math.floor(A * x / B)
    j = A * (math.floor(x / B))
    result = i - j
    lists.append(result)
print(lists[-1])

Submission status: Wrong Answer

Solution code:
import sys
import heapq
input = sys.stdin.readline
A,B,N=map(int,input().split())
Z=[]
if A<B:
    for x in range(N+1):
        Y=int(A*x/B)-A*int(x/B)
        Z.append(Y)
        if Y<Z[x-1]:
            print(Z[x-1])
    print(Z[N])
else:
    Y=int(A*N/B)-A*int(N/B)
    print(Y)

Submission status: Wrong Answer

Solution code:
a,b,n=map(int,input().split())
m=0
for x in range(b-50000,b+1):
    if x<0:continue
    m=max(int(a*(x-1)/b)-a*int((x-1)/b),int(a*x/b)-a*int(x/b))
print(m)

Submission status: Wrong Answer

Solution code:

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

if b <= n:
    k = math.floor(n/b)
    ans = max(math.floor(a*(b-1)/b), math.floor(a*n/b)- a*math.floor(n/b),math.floor(a*(k*b-1)/b)-a*math.floor((k*b-1)/b))
    print(ans)
else:
    print(math.floor(a*n/b))

Submission status: Wrong Answer

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

ans = 0
if A==B and A>=N:
  print(N)
elif B-1<=N:
  ans = int(A*(B-1)/B)-A*int((B-1)/B)
  print(ans)
else:
  ans = int(A*(N-1)/B)-A*int((N-1)/B)
  print(ans)

Submission status: Wrong Answer

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from operator import itemgetter
from collections import defaultdict
import sys
import math
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    a, b, n = wi()
    print(int(a*(b-1)/b) - a*int((b-1)/b))
    """
    for i in range(1, b+1):
        print(int(a*i/b) - a*int(i/b))
        c.append(int(a*i/b) - a*int(i/b))
        if i >= b:
            break
    print(max(c))
    """


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from math import floor
a,b,n = map(int,input().split())
x = b//n
x = x*n
x = x-1

print (max((floor((a*x/b) - a*(floor(x/b)))),(floor((a*n/b) - a*(floor(n/b))))))

Submission status: Wrong Answer

Solution code:
a,b,n = map(int,input().split())
x = 0
loop1 = n//b + 2
if loop1 > 10**5:
    loop1 = 10**5
    
loop2 = n//a + 2
if loop2 > 10**5:
    loop2 = 10**5

max_ = 0
    
if n < 10**8:
    for x in range(1, n + 1):
        tmp = (a*x)//b - a*(x//b)
        if tmp > max_:
            max_ = tmp

else:
    for x in range(1, 10**5):
        tmp = (a*x)//b - a*(x//b)
        if tmp > max_:
            max_ = tmp
    
    for x in range(n - 10**5, n):
        tmp = (a*x)//b - a*(x//b)
        if tmp > max_:
            max_ = tmp
            
    for i in range(1, loop1):
        x = i*b - 1
        if x > n:
            continue
        tmp = (a*x)//b - a*(x//b)
        if tmp > max_:
            max_ = tmp

    for i in range(1,loop2):
        x = i*b//a + 1
        if x > n:
            continue
        tmp = (a*x)//b - a*(x//b)
        print((a*x)//b,a*(x//b), tmp)
        if tmp > max_:
            max_ = tmp
    
print(max_)

Submission status: Wrong Answer

Solution code:
import math

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

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

if n <= b:
    print(calc(n-(a/(2*b))))
else:
    print(calc(b-(a/(2*b))))

Submission status: Wrong Answer

Solution code:
a,b,n = map(int, input().split())
def f(x):
    return int(a*x/b) - a*int(x/b)
syou = n//b
Max = 0
for i in range(0,a+1):
    syou1 = syou - i
    Max = max(f(syou1*b-1),f(syou*b-1),Max)
Max = max(Max,f(n),f((syou+1)*b-1))
print(Max)

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:
    n = int(N/B)
    for i in range(n-10,n+1):
        x = i*B
        temp = ans1 = int((A*(x-1))/B)-A*int((x-1)/B)
        if temp > ans:
            ans = temp
    n = n*B
    ans1 = int((A*(n-1))/B)-A*int((n-1)/B)
    ans3 = int((A*(n+1))/B)-A*int((n+1)/B)
    ans2 = int((A*(B-1))/B)-A*int((B-1)/B)
    ans4 = int((A*(B+1))/B)-A*int((B+1)/B)
    ans5 = int((A*(n))/B)-A*int((n)/B)
else:
    ans1 = ans
    ans2 = ans
    ans3 = ans
    ans4 = ans
    ans5 = ans


print(max(ans, ans1, ans2, ans3, ans4, ans5))

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt, floor

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


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


def main():
    a, b, n = MI()

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = 0

if b == 1:
  ans = 0

else:
  for x in range(0, a * n + 1, b):
    if x == b:
      ans = 0
    new = math.floor(x / b) - a * math.floor((x / a) / b)
    if new > ans:
      ans = new

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:
    #ans = math.floor(A*N/B) - A*math.floor(N/B)
    ans = (10**100)*(A*N)
    ans /= B
    print(int(ans // (10**100)))

Submission status: Wrong Answer

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


num=round(A*N/B)-A*round(N/B)


print(num)

Submission status: Wrong Answer

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



if (a*c)<b:
    print(0)
else:
    if b<c:
        max=0
        for i in range(b,c+1):
            d=math.floor(a*i/b)-a*math.floor(i/b)
            #print(math.floor(a*i/b))
            #print(a*math.floor(i/b))
            print(i)
            print(d)
            if max<d:
                max=d
        print(max)
    else:
        max=0
        e=int(a/b)
        for i in range(e,c+1):
            d=math.floor(a*i/b)-a*math.floor(i/b)
            #print(math.floor(a*i/b))
            #print(a*math.floor(i/b))
            print(i)
            print(d)
            if max<d:
                max=d
        print(max)


'''

for i in list1:

    if lv[i[1]-1]-lv[i[0]-1]==i[2]:
        #print(lv)
        #print(i)
        sum1+=i[3]


if max<=sum1:
    max=sum1




print(max)
'''

Submission status: Wrong Answer

Solution code:
from math import floor
A, B, N = map(int, input().split())
dic = {}
if N <= 10**6:
    for i in range(1, N+1):
        tmp = floor(A*i/B) - A*floor(i/B)
        if tmp in dic:
            dic[tmp] += 1
        else:
            dic[tmp] = 1
else:
    for i in range(1, 10**6+1):
        tmp = floor(A*i/B) - A*floor(i/B)
        if tmp in dic:
            dic[tmp] += 1
        else:
            dic[tmp] = 1
ans = -1
for k, v in dic.items():
    if k > ans:
        ans = k
print(ans)

Submission status: Wrong Answer

Solution code:
Ns,Ms,Qs=input().split()
A=int(Ns)
B=int(Ms)
N=int(Qs)
ans=-1*A
tmp=0
x=int(B/2)
ans=A*int(B/2)/B
print(int(ans))

Submission status: Wrong Answer

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

temp_prev = 0
temp_curr = 0
if b <= 100:
    x = 0.0
else:
    x = min(n, b-1)

while x <= n:
    temp_prev = temp_curr
    temp_curr = int(a * x / b) - a * int(x / b)
    x += 1.0

    if temp_curr <= temp_prev:
        break

print(max(temp_curr, temp_prev))

Submission status: Wrong Answer

Solution code:
import math

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

c = a/b
p = []

for x in range(n + 1):
    d = math.floor(c * x - a * math.floor(x / b))
    p.append(d)
    if len(p) == 2:
        del p[0]


print(p[0])

Submission status: Wrong Answer

Solution code:
a,b,n=map(int,input().split())
res=0
x=n
for x in range(min(b,n+1,1000000)):
    res=max(res,int(a*x/b)-a*int(x/b))
print(res)

Submission status: Wrong Answer

Solution code:
a,b,n=map(int,input().split())
if b-1<n:
    max_y=b-1
else:
    max_y=n
    
max_y_list=[]
count=1
while True:
    if b*count-1>max_y:
        max_y_list.append(n)
        break
    max_y_list.append(b*count-1)
    count+=1
    
# if a<max_y:
#     max_m=a
# else:
#     max_m=max_y


import math
ans=0
for i in max_y_list:
    f=math.floor(i*a/b)-a*math.floor(i/b)
    ans=max(ans,f)

print(ans)