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:
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
    cnt = 0
    for x in reversed(range(1,n+1)):
        mod = (a*x)%b
        cnt += 1
        if mod < min_mod:
            min_mod = mod
            v = divf(a*x,b) - a*(divf(x,b))
            maxv = max(maxv, v)
        else:
            if cnt > 10**5:
                break
    print(maxv)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

print(value)

Submission status: Wrong Answer

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

from decimal import *

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

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

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

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

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

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

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

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

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

inf = float('inf')
mod = 1000000007

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

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

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

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

	print(maxs)



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

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

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

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


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

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

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

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

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

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

def f(x):
  return floor(a*x/b) - a*floor(x/b)


if a*n < b:
  print(a-1)
else:  
  ans = 0
  for i in range(1,min(a+1,n+1)):
    ans = max(ans,f(i))
  print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math
 
A,B,N = map(int, input().split())
List=[]
i=1
count=0
while i<=N:
    one=math.floor((A*i)/B)
    two=math.floor(i/B)
    three=A*two
    ans=one-three
    List.append(ans)
    if ans==0:
        count+=1
        if count==10:
            break
    #print(ans)
    i+=1
#print("ans")
print(max(List))

Submission status: Wrong Answer

Solution code:
A, B, N = map(int, input().split())
# S = input()
# X1_list = [int(input()) for i in range(N)]
# X2_list = [list(map(int,input().split())) for i in range(N)]

if N < B:
    a = int(A * N / B)
    b = A * int(N / B)
    print(a - b)
    exit(0)

ans = 0
before_ans = 0
for i in range(1, N + 1,A):
    a = int(A * i / B)
    b = A * int(i / B)
    ans = max(ans, a - b)
    if before_ans > a - b:
        break
    if ans == min(A - 1, B - 1):
        break
    before_ans = a - b
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = []

for x in range(1,N+1):
    l.append( int((A*x)/B) - A*int(x/B) )

l.reverse()

print(l[0])

Submission status: Wrong Answer

Solution code:
import math

a, b, n = map(int, input().split())
x = 0
if n<=b:
	x = n%b
	print(int(a*x/b)-a*int(x/b))
	#print(int((a*((b-1)%b) - (a*(b-1))%b)/b))
else:
	if int(n/b) >=1:
		x = b-1
		print(int(a*x/b)-a*int(x/b))
	else:
		x = n
		print(int(a*x/b)-a*int(x/b))

Submission status: Wrong Answer

Solution code:
a, b, n = [int(i) for i in input().split(" ")]
x = b - 1
print((int((a * x) / b)) - 1 - a * (x // b))

Submission status: Wrong Answer

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

def judge(x):
  #print(x,math.floor(a*(x+1)/b)-math.floor(a*x/b),math.floor(x+1/b)-math.floor(x/b))
  if math.floor(a*(x+1)/b)-math.floor(a*x/b)>=a*(math.floor((x+1)/b)-math.floor(x/b)):
    
    return True 
  else:
    return False

def bi_re():
  l=1
  r=n
  
  while l<=r:
    m=(l+r)//2
    #print(m)
    if judge(m):
      l=m+1
    else:
      r=m-1
  return m
c=bi_re()
#print(c)
print(math.floor(a*c/b)-a*math.floor(c/b))

Submission status: Wrong Answer

Solution code:
import math
A,B,N=list(map(int,input().split()))
if B==1 or A==1:
    print(0)
elif N%B!=0:
    print(math.floor(A*N/B)-(A*math.floor(N/B)))
else:
    print(math.floor(A*(N-1)/B)-(A*math.floor((N-1)/B)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a,b,n=map(int,input().split())
x=[]
x.append(int(a*n/b)-a*int(n/b))
if n>=b:
  t=int(n/b)
  x.append(int(a*(t*b-1)/b)-a*int((t*b-1)/b))
x.append(int(a*(b-1)/b)-a*int((b-1)/b))
print(max(x))

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:
import math
A, B, N = (int(i) for i in input().split())  
ans = 0
for x in range(0, 100000):
  result = math.floor(A * x / B) - A * math.floor(x/B)
  ans = max(ans, result)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

S = []
max_value = 0

for i in range(1, N+1):
    S.append(math.floor(A*i/B) - A* math.floor(i/B))

for j in range(len(S)-1):
     if S[j+1] - S[j] >= max_value:
        max_value = S[j+1]

    
print(max_value)

Submission status: Wrong Answer

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

if b == 1:
    r = [0]
else:
    i = 0
    r = []
    while b*i-1 <= n:
        r.append(int((a*(b*i-1))/b)-a*int((b*i-1)/b))
        i += 1
print(max(r))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for x in reversed(range(n+1)):
    tmp = math.floor(a*x/b) - a * math.floor(x/b)
    if tmp > ans:
        ans = tmp
        exit()

print(ans)

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:
#coding:utf-8

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

z = 0

if n < b:
    z = n * a // b
else:
    z = a - 1

print("{}".format(z))

Submission status: Wrong Answer

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

print((A*(B-1)) // B - A * ((B -1) // B))

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
	if(n>b):
		f = math.floor((a*(b-1))/b)
		s = math.floor((b-1)/b)
		temp = int(f) - (a*int(s))
		ans = temp
	else:
		f = math.floor((a*(n-1))/b)
		s = math.floor((n-1)/b)
		temp = int(f) - (a*int(s))
		ans = temp
	print(ans)

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)

    B_A = 1.0 * B / A

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

        x_2 = int(B_A * i)
        if x_2 > N:
            break
        v = target(x_2)
        # 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())

def F(x):
    return (a*x//b)-a*(x//b)

l=0
r=n+1
ans1=0

for i in range(60):
    m=(r+l)//2
    f=F(m)
    f0=F(max(0,m-1))
    f1=F(min(n,m+1))
    A=max([f,f0,f1])
    #print(m,f,ans1)
    if A>ans1:
        ans1=A
        l=m
    else:
        r=m
    
#print(ans1)
#print(F(500))



ans2=0
if n==1:
    print(0)
elif n<=10**6:
    for i in range(n+1):
        f=F(i)
        if f>ans2:
            ans2=f
        #print(i,ans)
#print(ans2)
    print(ans2)
else:
    print(ans1)

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(min(a-1,b-1),y,x))

Submission status: Wrong Answer

Solution code:
A, B, N = map(int, input().split())
ans = -float('inf')

for x in range(N, 0, -1):
    a = (A*x) // B - A * (x // B)
    ans = max(ans, a)
    if ans > a:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import math

def main(A, B, N):
    answer = 0
    for x in range(N):
        cand = math.floor(A * x / B) - A * math.floor(x / B)
        answer = max(answer, cand)
    print(answer)



if __name__ == '__main__':
    A, B, N = list(map(int, input().split()))
    # A, B, N = 5, 7, 4
    main(A, B, N)

Submission status: Wrong Answer

Solution code:
li=list(map(int,input().split()))
a=li[0]
b=li[1]
n=li[2]
c=int((a*n)/b)
d=int(n/b)

if c>=0:
  e=int(c-a*d)
  print(e)

Submission status: Wrong Answer

Solution code:
import math

a,b,n = map(int, input().split())
tmp = int(n/b)
result = 0
if tmp != 0:
    result = b*tmp - 1
else:
    result = n
if result + b <= n: result = n
print(math.floor((a*result)/b) - a*math.floor(result/b))

Submission status: Wrong Answer

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

x = N if N < B else (N // B) * B - 1

print(math.floor(A * x / B)- A * math.floor(x / B))

Submission status: Wrong Answer

Solution code:
a, b, n = map(int, input().split())
x = 0
m = 0
for x in range(b-10000000,b):
  value = a*x//b - a*(x//b)
  if value > m:
    m = value
print(m)

Submission status: Wrong Answer

Solution code:
a, b, n = map(int, input().split())
tmp = n
ans = int((a * n) / b) - a * int(n / b)
n = tmp - 1
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = tmp - 2
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = tmp - 3
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = tmp - 4
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = tmp - 5
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = tmp - 6
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = tmp - 7
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = tmp - 8
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = tmp - 9
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = tmp - 10
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = min(tmp, 1)
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = min(tmp, 2)
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = min(tmp, 3)
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = min(tmp, 4)
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = min(tmp, 5)
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = min(tmp, 6)
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = min(tmp, 7)
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = min(tmp, 8)
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = min(tmp, 9)
ans = max(ans, int((a * n) / b) - a * int(n / b))
n = min(tmp, 10)
ans = max(ans, int((a * n) / b) - a * int(n / b))
print(ans)

Submission status: Wrong Answer

Solution code:
import math
 
a = list(map(int, input().split()))
A = a[0]
B = a[1]
N = a[2]

if N%B !=0:
  x_1 = (N//B)*B-1
  if x_1 == -1:
    x_1 = N
  x_2 = N
elif N == 1:
  x_1=N
  x_2 =N
else:
  x_1 = N-1
  x_2 = N-1
ans_1 = math.floor(A*x_1/B)-A*math.floor(x_1/B)
ans_2 = math.floor(A*x_2/B)-A*math.floor(x_2/B)
if ans_1 >= ans_2:
  print(ans_1)
else:
  print(ans_2)

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

list = {}
a = 0
b= 0
c=0
d=0
for i in range(N + 1, 1, -1):
    if (A*i)%B == int(6):
        a = int(A * i/B) - A * int(i/B)
    elif (A * i) % B == int(7):
        b = int(A * i / B) - A * int(i / B)
    elif (A * i) % B == int(8):
        c = int(A * i / B) - A * int(i / B)
    elif (A * i) % B == int(9):
        d = int(A * i / B) - A * int(i / B)
        break

print(max(a,b,c,d))

Submission status: Wrong Answer

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

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

def solve(A: int, B: int, N: int):
    def func(x):
        return math.floor(A/B * (x%B))

    leftmost = 1
    rightmost = min(N,B)
    midpoint = rightmost // 2

    # for _ in range(10**5):
    #     y = func(rightmost)
    #     if y < N:
    #         leftmost = midpoint
    #     elif y > N:
    #         rightmost = midpoint
    #     else:
    #         break

    #     midpoint = (leftmost+rightmost) // 2
    
    midpoint = min(N,B)
    if midpoint == 1:
        midpoint = max(N,B)
    ans = math.floor(A*midpoint/B) - A*math.floor(midpoint/B)
    print(ans)

    # i = 0
    # over_N =0
    # while over_N < N:
    #     x = 10 * 10**i
    #     over_N = func(A, B, x)
    #     i += 1

    # while True:
    #     out = func(A, B, x)
    #     if  out <= N:
    #         break
    #     else:
    #         x -= 1

    # print(func(A, B, x))
    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().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())

def fl_m(a,b,n):
  if n>b:
    z=a-1
  elif n==b and b/a>=1:
    z=a-1
  elif n==b and b/a<1:
    z=a+math.floor(-a/b)
  elif a*n/b-int(a*n/b)==0:
    z=int(a*n/b)
  elif b/a>=1:
    z=int(a*n/b)
  else:
    g=math.gcd(a,b)
    M=int(a/g)
    if M>n-1:
      z=0
    else:
      z=int(n/M)*M
  return(z)
    
print(fl_m(A,B,N))

Submission status: Wrong Answer

Solution code:
# A, B, N = map(int, input().split())
A, B, N = 5, 7, 4

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

def calculate(a, b, n):
    s1 =  (a * n) // b
    if n == b:
        s1 = a*(n-1) // b
    if n > b:
        if n >= 2 * b:
            x = b + b - 1
        else:
            x = n
        return max(s1,(a * x) // b + a * (x // b))

    return s1


print(calculate(A, B, N))

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 A == 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())
ans=a*n
print(math.floor(ans/b))

Submission status: Wrong Answer

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

number = []
number.append(min(b, n))
current = b*2
while current-1 <= n:
    # number.append(current-1)
    current += b
number.append(current-b-1)

max_v = 0
for x in number:
    v = math.floor(a*x/b) - a * math.floor(x/b)
    max_v = max(v, max_v)

print(max_v)

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-

def main():
    a, b, n = map(int, input().split())
    ans = 0
    if b > n:
        ans = (a * n) // b
    elif b == n:
        ans = (a * (n - 1)) // b
    else:
        ans = (a * b) // b
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
A,B,N=map(int,input().split())
S=[0]
for x in range(0,N):
  S.append(int((A*x)/B)-A*int(x/B))
print(max(S))

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-100,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:
A,B,N = list(map(int,input().split()))
if N <= 10000000:
    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(100)]
D = [A*i//B-(A*(i//B)) for i in range(N,N-100,-1)]
print(max(max(C),max(D)))

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

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

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

Submission status: Wrong Answer

Solution code:
A, B, N = map(int, input().split())
ans = 0
ans_max = 0
for x in reversed(range(1,N+1)):
    ans = int(float(A*x)/float(B))-A*int(float(x)/float(B))
    if ans_max < ans:
        ans_max = ans
    if x < N-A or x < N-B:
        break
print(ans_max)

Submission status: Wrong Answer

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

cnt=0
while(True):
  if 0<int(A*cnt/B):
    break
  else:
    cnt+=1
cnt=cnt-1
if N<B:
  print(int(A*N/B)-A*int(N/B))
else:
  print(int(A*cnt/B)-A*int(cnt/B))

Submission status: Wrong Answer

Solution code:
a,b,n = map(int, input().split())
sumtemp=0
summax=0
for x in range(1,b):
    sumtemp=int(a*x/b)-a*int(x/b)
    if sumtemp>summax:
        summax=sumtemp
print(sumtemp)

Submission status: Wrong Answer

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

def keisan(a, b, x):
    return ((a*x)//b)-a*(x//b)

print(max(list(map(lambda y: keisan(a, b, y) ,range(1,b+1)))))