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:
A,B,N = map(int, input().split())
ans = -10**1000
Flag = True
for x in range(1, N+1, max(1, int(B/A))):
    a = int(A*x/B) - A*int(x/B)
    if a>ans:
        ans = a
        Flag = True
    elif Flag:
        Flag = False
    else:
        break

a = int(A*N/B) - A*int(N/B)
if a>ans:
    ans = a
print(ans)

Submission status: Wrong Answer

Solution code:
l = list(map(int,input().split()))
a = l[0]
b = l[1]
n = l[2]

def floor(a,b,x):
    p = (a*x)//b - a*(x//b)
    return p

max = 0
maxn = 0
for i in range(n+1):
    c = floor(a,b,i)
    if c >= max:
        max = c
        maxn = i

print(maxn)

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-250), -1):
    n = math.floor(a*x/b) - a * math.floor(x/b)
    if ans <= n:
      ans = n
  
print(ans)

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):
    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:
A,B,N=[int(x) for x in input().rstrip().split()]
ans=0
now=0
aa=0

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

# if N<B:
#   print(int(A*N/B)-A*int(N/B))
# else:
#   print()

Submission status: Wrong Answer

Solution code:
A,B,N = list(map(int,input().split()))
if N <= 10000:
    C = [A*i//B-(A*(i//B)) for i in range(1,N+1)]
    print(max(C))
    exit()
C = [A*i//B-(A*(i//B)) for i in range(1000000)]
D = [A*i//B-(A*(i//B)) for i in range(N,N-1000000,-1)]
E = [A*i//B-(A*(i//B)) for i in range(N//2-1000000,N//2+1000000)]
print(max(max(C),max(D),max(E)))

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(0, min(a + 5, n + 1)):
    # print(i)
    # print(calc(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())
ans = []
for x in range(0, 10**6):
    cal = math.floor((A*x)/B) - (int(A) * math.floor(x/B))
    ans.append(cal)
for x in range(N-10**6, 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:
# -*- coding: utf-8 -*-
a, b, n = list(map(int, input().split()))
max_value = 0
trial = 100000
for x in range(0, trial):
    x = n - x
    # print('x', x)
    tmp = (x*a//b) - a*(x//b)
    # print(x*a//b, a*(x//b))
    # print('ans', tmp)
    # print('============')
    if (tmp > max_value):
        max_value = tmp
print(max_value)

Submission status: Wrong Answer

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

def solve(A: int, B: int, N: int):
    result1 = int(A*(B-1)/B) - A * int((B-1) / B)
    result2 = int(A*N/B) - A*int(N/B)
    print(min(result1, result2))
    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
 
A, B, N = map(int, input().split())
c = 0
for x in range(N, 1, -1):
    j = (A*x / B)
    k = (x / B)
    a = math.floor(j) - A * math.floor(k)
    if a < c :
        break
    c = a
print(c)

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), int(a%b), int(b%a))-1, -1):
        tmp = int((a*i)/b) -a * int(i/b)

        #print(i)
        #print(tmp)
        if max_int < tmp:
            max_int = tmp

print(max_int)

Submission status: Wrong Answer

Solution code:
import math
a,b,n = map(int,input().split())
ans = -float("inf")
for x in range(max(1,n-b),n+1):
    num = math.floor(a*x/b) - a*(math.floor((x/b)))
    #print(num)
    if num > ans:
        ans = num
    """else:
        print("/---")
        print(num)
        print("---------")"""
print(ans)

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)
            break
elif B == N :
    An = fl(N-1)

print(str(An))

Submission status: Wrong Answer

Solution code:
import math


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

    def target(x):
        # print(math.floor(A * x / B))
        # print(A * math.floor(x / B))
        return math.floor(A * x / B) - A * math.floor(x / B)

    max_value = -1
    for i in range(1, int(min(N + 1, B + 1) / (1.0 * B / A))):
        x = (B / A) * i
        v = target(x)
        # print(f'x={i} f(x)={v}')
        if v > max_value:
            max_value = v
    print(max_value)


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)

if N > 100000:
    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)

else:
    temp = 0
    for i in range(N+1):
        temp = max(temp,f(i))
    print(temp)

Submission status: Wrong Answer

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

y = int(a*bdash/b)-a*int(bdash/b)

print(max(a-1,y,x))

Submission status: Wrong Answer

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

if A == 1 or B == 1:
  print(0)
  sys.exit()

ra = []
for i in reversed(range(1, N+1)):
  temp = math.floor(A * i / B) - (A * math.floor(i / B))
  if not temp in ra:
    ra.append(temp)
  else:
    if temp > 0:
      break
  
print(max(ra))

Submission status: Wrong Answer

Solution code:
from math import floor
A,B,N=list(map(int,input().split()))
ans = 0
for x in range(N,0,-1):
  a = floor(A*x/B)-A*floor(x/B)
  if ans <= a:
    ans = a
  if B<x:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
A,B,N = map(int, input().split())
print(round(A*(N-1)/B)-A*int((N-1)/B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

def floor_t(A,B,y):
    return math.floor(A*y/B) - A*math.floor(y/B)

total = 0

# if A==B:
#     if A-1<=N:
#         print(floor_t(A,B,A-1))
#         exit(0)
#     else:
#         print(floor_t(A,B,N))
#         exit(0)

if N<B:
    for x in range(N+1):
        if x%B==0:
            continue
        else:
            total = max(total,floor_t(A,B,x))

else:
    for x in range(B,N+1):
        if x%B==0:
            continue
        else:
            total = max(total,floor_t(A,B,x))










print(total)

Submission status: Wrong Answer

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

def binary_search():
    low = 1
    high = n

    m = -999999999999

    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())
ans=0
for x in range(1,b+1):
    tui=math.floor(a*x/b)-a*math.floor(x/b)
    ans=max(ans,tui)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

m = b/a


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, N = map(int,input().split())
import math
C = N % B
ans = []
x1 = N
x2 = N-C-1
if x2 < 0:
    x2 =0

def f(x):
    return math.floor(A*x/B)-A*math.floor(x/B)
if N >B:
    for k in range(x2, x1+1):
        ans.append(f(k))
ans.append(f(N))
ans.append(f(N-1))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    a, b, n = MII()
    maxv = 0
    min_mod = b
    for x in reversed(range(1,n+1)):
        mod = (a*x)%b
        v = divf(a*x,b) - a*(divf(x,b))
        maxv = max(maxv, v)
        if mod < min_mod:
            min_mod = mod
        else:
            break
    print(maxv)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = -1
if(a % b == 0):
    x = b-1
    abc = ((a*x)//b)-(a*(x//b))
    if(ans < abc):
        ans = abc
elif(n < 10 ** 8):
    for x in range(1,n+1):
        abc = ((a*x)//b)-(a*(x//b))
        if(ans < abc):
            ans = abc
else:
    for x in range(n-int(n**(1/2)),n+1):
        abc = ((a*x)//b)-(a*(x//b))
        if(ans < abc):
            ans = abc


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

ans = 0

#bがnよりも大きい時
if b > n:
    ans = int(a*n/b)
    print(ans)
    exit()

#b==nのときは、終了間際の2個だけ比較する
elif b == n:
    for i in range(n-1,n+1):
        tmpans = int(a*i/b) - (a*int(i/b))
        if tmpans >= ans:
            ans = tmpans
    print(ans)
    exit()

#これ以外の時は、nはb値ごとにスキップする。
else:
    for i in range(1,n+1,a*b):
        tmpans = int(a*(i-2)/b) - (a*int((i-2)/b))
        if tmpans >= ans:
            ans = tmpans
    for i in range(n-1,n+1):
        tmpans = int(a*i/b) - (a*int(i/b))
        if tmpans >= ans:
            ans = tmpans

print(ans)

Submission status: Wrong Answer

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

def main():
    A,B,N = map(int,input().split())
    if N <= B-1:
        ans = cal(A,B,N)
    else:
        d = N // B
        if N % B == 0:
            ans = cal(A,B,B*d-1)
        else:
            if B*(d+1)-1 <= N:
                ans = cal(A,B,B*(d+1)-1)
            else:
                ans = cal(A,B,B*d-1)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
def fs(A, B, x):
    return math.floor(A*x/B) - A * math.floor(x/B)


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

    low = 0
    high = N + 1

    ans = fs(A, B, low)

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

    #print(low, high)
    print(max(fs(A, B, low), fs(A, B, high)))
    return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import math

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

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

result = calc(a[0], a[1], a[2])
# for i in range(1, a[2]+1):
#     result = max(result, calc(a[0], a[1], i))
#     print(calc(a[0], a[1], i))


print(result)

Submission status: Wrong Answer

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


import math
max_y=max_y_list
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)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
a, b, n = map(int, input().split())
x= int((1-a)/b)
max = -99999
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:
def main():
  import math
  A, B, N = map(int, input().split())
  p = 0
  tobi = B / A
  
  y_0 = math.ceil(tobi * ((int(N / tobi) //2 )+1))
  y_1 = math.ceil(tobi * ((int(N / tobi) //2 )+2))
  y_2 = math.ceil(tobi * ((int(N / tobi) //2 )+3))
  start_0 = ((A * y_0) // B) -  (A *(y_0 // B))
  start_1 = ((A * y_1) // B) -  (A *(y_1 // B))
  start_2 = ((A * y_2) // B) -  (A *(y_1 // B))
  
  if start_2 > start_1: 
    for i in range(int(N / tobi) //2 ,int(N / tobi)):
      x = math.ceil(tobi * (i+1))
      score = ((A * x) // B) -  (A *(x // B))
      if score > p:
        p = score

  else:
    for i in range(0 ,(int(N / tobi) //2)+1, -1):
      x = math.ceil(tobi * (i+1))
      score = ((A * x) // B) -  (A *(x // B))
      if score > p:
        p = score
     
  print(p)
 
main()

Submission status: Wrong Answer

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

if N < B:
    print((A*N)//B)
else:
    ans = 0
    # q = B
    # c = 1
    # while N > q:
    #     q = B*c
    #     n = A*c - A*c
    #     print(n)
    #     ans = max(ans,n)
    #     c += 1
    
    print(ans)

Submission status: Wrong Answer

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

ans = set()

if N <= B :
  print(int(N * A / B) - A * int(N / B))
  sys.exit()
else :
  for i in range(B) :
    ans.add(int((B-1) * A / B) - A * int((B-1) / B))

print(max(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

ABN=np.array(input().split(" "),dtype=np.int32)
A=ABN[0]
B=ABN[1]
N=ABN[2]

out=0
for x in range(N+1):
    calc=int(A*x/B)-A*int(x/B)
    if(calc>out):
        out=calc

print(out)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if(N<10**8):
  for i in range(N+1)[::-1]:
    maxlist.append(func(A,B,i))
else:#N>10**8
  for i in range(N-10**6,N+1)[::-1]:
    if(func(A,B,i)==A-1):
      maxlist.append(func(A,B,i))
      break
    else:
      maxlist.append(func(A,B,i))
  
print(max(maxlist))

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 = (x / b - 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:
A, B, N = map(int, input().split())

# maxn = -10
# S = min(B,N)
# for x in range(N):
#     tmp = int(A*x/B)-A*int(x/B)
#     if tmp > maxn:
#         maxn = tmp
#     print(x,tmp)
x = min(B, N)
max_num = 0
for i in range(x-3,x+3):
    max_num = max(max_num,int(A*i/B)-A*int(i/B))
print(max_num)

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:
    if x > n:
        pass
    else:
        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())
ans = max(int(a * (n) / b) - a * int((n) / b), int(a * (n - 1) / b) - a * int((n - 1) / b))
for i in range((n + 1 - 100000), n + 1)[::-1]:
    if n >= i and i > 0:
        floor = int(a * i / b) - a * int(i / b)
        ans = max(ans, floor)
for i in range(100000):
    if n >= i and i > 0:
        floor = int(a * i / b) - a * int(i / b)
        ans = max(ans, floor)
print(ans)

Submission status: Wrong Answer

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

from math import floor

maxi = 0
for i in range(min(n+1, 100001)):
    maxi = max(maxi, floor((a*(n-i))/b) - a*floor((n-i) / b)) 
    maxi = max(maxi, floor((a*(i))/b) - a*floor((i) / b))
print(int(maxi))

Submission status: Wrong Answer

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

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

print(answer)

Submission status: Wrong Answer

Solution code:
import math
import sys

a, b, n = map(int, input().split())
step = math.ceil(n/(10**6))
array = range(1, n+1, step)
ans = -sys.maxsize-1

for x in array:
    val = int((a*x)/b) - a*int(x/b)
    if val > ans:
        ans = val

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 = (x_max +x_min)/2.0
        
        x_mid_max = (x_max +x_mid)/2.0
        x_mid_mim = (x_min +x_mid)/2.0
        
        #探索区間を更新
        if func_f(A,B,x_max) < func_f(A,B,x_mid):
            x_min = x_mid
        elif func_f(A,B,x_min) < func_f(A,B,x_mid):
            x_max = x_mid
        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
A, B, N = map(int, input().split())
ans = []
for x in range(0, 10**5):
    cal = math.floor((A*x)/B) - (int(A) * math.floor(x/B))
    ans.append(cal)
for x in range(N-10**5, 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:
A, B, N = map(int, input().split())

if B > N:
    ans = int(A*N/B)
    print(ans)
else:
    ans = 0
    ans_2nd = 0
    x = (N//B)*B - 1
    temp = int(A*x/B) - A*int(x/B)
    # while ans <= temp and x >= 0:
    #     ans = temp
    #     temp = int(A*x/B) - A*int(x/B)
    #     x -= B
    # while ans_2nd <= temp and x >= 0:
    #     ans_2nd = temp
    #     temp = int(A*x/B) - A*int(x/B)
    #     x -= B
    # print(max(ans, ans_2nd))
    print(temp)

Submission status: Wrong Answer

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

import math

x = n
tmp1 = math.floor(a*x/b) - a*math.floor(x/b)
ret = tmp1

if n//b == 0:
    print(tmp1)
else:
    q, _ = divmod(n, b)
    for i in range(q,q-10**4,-1):
        x = i*b-1
        tmp2 = math.floor(a*x/b) - a*math.floor(x/b)
        ret = max(ret, tmp2)
    print(ret)

Submission status: Wrong Answer

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

ans = 0
for i in range(min(A+1, N+1)):
    tmp = ((A*i)//B) - (A*(i//B))
    if tmp >= ans:
        ans = tmp
        
print(ans)

Submission status: Wrong Answer

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

tmp = 0
a = 0
i = 0
past = 0

if i >= N - B:
    for i in range(N, N - N % B - 1, -1):
        if (s := (A * i) // B - A * (i // B)) > 0:
            tmp = max(s, tmp)
        else:
            break

print(tmp)

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):
    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:
A,B,N = map(int, input().split())
import math
max = 0
n = 1
for x in range(min(N,B)):
    y = math.floor((A*x)/B) - A*math.floor(x/B)
    if(max<y):
        max = y
    
while(B*n <= N):
    x = B*n -1
    y = math.floor((A*x)/B) - A*math.floor(x/B)
    if(max<y):
        max = y
    n += 1

print(max)

Submission status: Wrong Answer

Solution code:
import math
if __name__ == "__main__": 
	string = input()
	l = string.split(" ")
	a = int(l[0])
	b = int(l[1])
	n = int(l[2])
	ans = 0
	# for i in range(1,n+1):
	# 	f = math.floor((a*i)/b)
	# 	s = math.floor(i/b)
	# 	temp = int(f) - (a*int(s))
	# 	print(temp,(a*i)/b, a*int(s), i)
	# 	if(temp > ans):
	# 		ans = temp
	if(b>=n):
		f = math.floor((a*(n-1))/b)
		ans = int(f)
		
	else:
		f = math.floor((a*(b-1))/b)
		ans = int(f)
	print(ans)

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)

    print(int(ans))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import math
def fs(A, B, x):
    return math.floor(A*x/B) - A * math.floor(x/B)


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

    low = 0
    high = N

    ans = fs(A, B, low)

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

    #print(low, high)
    print(max(fs(A, B, low), fs(A, B, high)))
    return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
a, b, n = map(int, input().split())
ans = 0
p = 0
for i in reversed(range(1, n+1)):
    t = math.floor(a*i/b) - a * math.floor(i/b)
    if ans < t:
        ans = t
    if p > t:
        break
    else:
        p = t

print(ans)

Submission status: Wrong Answer

Solution code:
A,B,N = input().split()
A = int(A)
B = int(B)
N = int(N)
ans = 0
for x in range(N):
    
    if x < B:
        z = A*x
        if z < B:
            ans_2 = 0
        else:
            ans_2 = (z)//B
    else:
        z_2 = x//B
        ans_2 = (z)//B - (A * (z_2))
    if ans < ans_2:
        ans = ans_2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import math

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

    # for i in range(n, 0, -1):
    #     print(i, math.floor((a * i) / b) - a * math.floor(i / b))

    # if n // b * b - 1 >= 0:
    if b <= n:
        n = n // b * b - 1


    # while 1:
    #     if (a * n) % b == 0 and n % b == 0:
    #         n -= 1
    #     else:
    #         break


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

    # print('ans')
    # print(n, ans)
    print(int(ans))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5 7 4"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """11 10 9"""
        output = """9"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

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(int((A*i)/B)-A*int(i/B),maxi)
    for i in range(N-2*10**6,N+1):
        maxi = max(int((A*i)/B)-A*int(i/B),maxi)
else:
    for i in range(0,N+1):
        maxi = max(int((A*i)/B)-A*int(i/B),maxi)
print(max(maxi,0))

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(2000000)
# import itertools
# import statistics
# import numpy as np
# x = int(input())
a, b, n = list(map(int, input().split()))
# a, b = list(map(int, input().split()))
# sy, sx = map(int, input().split())
# gy, gx = map(int, input().split())

ans = a*n//b - a*(n//b)
count = 0
same = 0

for i in range(n, int(pow(n, 0.5))-1, -1):
    if ans < a*i//b - a*(i//b):
        ans = a*i//b - a*(i//b)
        if count == 1:
            print(ans)
            exit()
    elif a*i//b - a*(i//b) == 0:
        count += 1
    elif a*i//b - a*(i//b) == ans:
        same += 1
    if same > 10:
        print(ans)
        exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

print(i)

Submission status: Wrong Answer

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