Problem:


Score : 400 points

Problem Statement

Given are integers A, B, and N.

Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.

Here floor(t) denotes the greatest integer not greater than the real number t.

Constraints

1 ≤ A ≤ 10^{6}

1 ≤ B ≤ 10^{12}

1 ≤ N ≤ 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B N

Output

Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.

Sample Input 1

5 7 4

Sample Output 1

2

When x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.

Sample Input 2

11 10 9

Sample Output 2

9



Sample input:
5 7 4


Sample output:
2

Submission status: Wrong Answer

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

from decimal import *

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

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

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

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

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

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

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

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

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

inf = float('inf')
mod = 1000000007

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

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

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

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

	print(maxs)



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

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

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

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


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

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

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

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

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

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def calc(A, B, N):
    return max(map(lambda x: int(A * x / B) - A * int(x / B), range(N - 2, N + 1)))


def main():
    A, B, X = list(map(int, input().split(' ')))
    print(calc(A, B, X))


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 ** 6):
    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:
a,b,n=map(int,input().split())
ans=0
for x in range(n+1):
  ab=a*x//b-x//b*a
  if n >= max(ab,ans):
    ans=ab
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import floor

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math

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

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

print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

ans = formula(A, B, X)

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A,B,N = (int(x) for x in input().split(' '))

import sys

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

  if ans > max:
    max = ans

print(max)

Submission status: Wrong Answer

Solution code:
import math
a,b,c=map(int,input().split())
max=0
for i in range(c):
    d=math.floor(a*i/b)-a*math.floor(i/b)

    if max<d:
        max=d
print(d)

Submission status: Wrong Answer

Solution code:
import math
a,b,n=map(int,input().split())
max=-2
if b<n:
    n=b
for i in range(1,n+1):
    if i<b:
        s=math.floor(a*i/b)
    else:
        continue
    if s>max:
        max=s
print(int(max))

Submission status: Wrong Answer

Solution code:
import math

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

if a == 1 or b == 1:
    print(0)
    exit()
    

l_n = n - 1
r_n = n - (n%b+1)


print(max(math.floor(a*l_n/b)- a*math.floor(l_n/b), math.floor(a*r_n/b)- a*math.floor(r_n/b)))

Submission status: Wrong Answer

Solution code:
def main():
    a, b, n = map(int, input().split())
    max = int(a*n/b)
    if n >= b:
        _ = n//b
        x = b*_-1
        num1 = int(a*n/b)-a*int(n/b)
        num2 = int(a*x/b)-a*int(x/b)
        if num1 < num2:
            ans = num2
        else:
            ans = num1
        if ans > max:
            max = ans

    return max

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

Submission status: Wrong Answer

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

print((a * n) // b - a * (n // b))

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
A, B, N = map(int, input().split())
max = 0
wait = int((B/A) + 1)
for x in range(1, N+1, wait):
    fun = int(A*x/B) - A*int(x/B)
    if x == 1:
        x0 = fun
    elif x > wait:
        if x0 == fun:
            break
    if max < fun:
        max = fun
print(max)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math

A, B, N = list(map(int, stdin.readline().rstrip().split()))

ans = []

x = max(1, math.gcd(B, N))
while x <= N:
    x += B
    ans.append(math.floor(A * x / B) - A * math.floor(x / B))

print(max(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
a,b,n = map(int, input().split())
#1 <= x <= n
#minimize  int(x/b)
#x = int(a*x/b) - a * int(x/b)
k = n%b
#def func(arr):
  #changed_array = int(a*arr/b) - a * int(arr/b)
  #return changed_array 
  
if n <= b:
  print(int(a*n/b) - a * int(n/b))
else:
  x = n-k-1
  print(int(a*x/b) - a * int(x/b))

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

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(1,10**4):
        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:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

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

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

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

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

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

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

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

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

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

inf = float('inf')
mod = 1000000007

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

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

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

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

	print(maxs)



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

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

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

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


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

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

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

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

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

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
input_line = list(map(int, input().split()))

A = input_line[0]
B = input_line[1]
N = input_line[2]

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

Submission status: Wrong Answer

Solution code:
import math
a,b,c=map(int,input().split())
max=0
for i in range(c):
    d=math.floor(a*i/b)-a*math.floor(i/b)
    print(d)
    if max<d:
        max=d
print(d)

Submission status: Wrong Answer

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


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

    x = (n // b) * b - 1
    if x < 0:
        x = n
    r = max(int(a * x / b) - a * (x // b),
            int(a * n / b) - a * (n // b))
    print(r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 0

if b == 1:
  ans = 0

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

print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
a,b,n=map(int,input().split())
cnt=0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

else:
    ans = 0
    r = min(n-b, b) * 2
    for i in range(r + 1):
        x = n - i
        v1 = math.floor(a*x/b)
        v2= a * math.floor(x/b)
        v =  v1 - v2
        print(x, a, x/b, v1, v2, v)
        ans = max(ans,v)

print(ans)

Submission status: Wrong Answer

Solution code:
#abc165_d.py
I = input().split()
A = int(I[0])
B = int(I[1])
N = int(I[2])

Max = 0
y = 0

Range = N % B

for i in range(1,Range+1):
    ans = (i * A - (i * A) % B)// B
    #print(ans, i)
    if(Max < ans):
        Max = ans

print(Max)

Submission status: Wrong Answer

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

def solve(A: int, B: int, N: int):
    result1 = A - math.ceil(A/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())

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import math
def f(x,y,z):
    # x,y,z = A,x,B
    return math.floor(x*y/z) - x*math.floor(y/z)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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(x if x>y else y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n >= b:
    n1 = n - n % b
    n2 = n - n % b - 1
    for x in range(1, n1+1, -b):
        tmp = math.floor(a * x / b) - a * math.floor(x / b)
        ans = max(ans, tmp)
    for x in range(1, n2+1, -b):
        tmp = math.floor(a * x / b) - a * math.floor(x / b)
        ans = max(ans, tmp)
    tmp = math.floor(a * n / b) - a * math.floor(n / b)
    ans = max(ans, tmp)
else:
    ans = math.floor(a * n / b) - a * math.floor(n / b)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
#二分法による非線型方程式の解法プログラム
import 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=1e-10, max_loop=100):
    #初期値を表示
    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:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

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

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

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

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

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

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

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

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

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

inf = float('inf')
mod = 1000000007

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

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

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

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

	print(maxs)



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

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

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

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


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

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

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

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

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

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

ans = 0
for x in range(N+1):
  A_x = A * x
  fnc_ = int(A_x / B) - A * int(x / B)
  if fnc_ <= N:
    ans = max(ans, fnc_)

print(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))

Submission status: Wrong Answer

Solution code:
import math
num = list(map(int, input().split()))
check = True
x = num[2]
while check:
    result = math.floor(num[0] * x / num[1]) - num[0] * math.floor(x/ num[1])
    if(result > num[2]):
        x -= 1
    else:
        check = False
print(result)

Submission status: Wrong Answer

Solution code:
import math

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