Problem:


Score : 400 points

Problem Statement

Given are integers A, B, and N.

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

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

Constraints

1 ≤ A ≤ 10^{6}

1 ≤ B ≤ 10^{12}

1 ≤ N ≤ 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B N

Output

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

Sample Input 1

5 7 4

Sample Output 1

2

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

Sample Input 2

11 10 9

Sample Output 2

9



Sample input:
5 7 4


Sample output:
2

Submission status: Runtime Error

Solution code:
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }

// 整数の桁数を返す ( log(N) )
template <class Integer> Integer GetDigit(Integer n) {
    if (n == 0) return 1;
    Integer d = 0;
    while (n) {
        n /= 10;
        d++;
    }
    return d;
}

// 素数かどうかを返す ( O(sqrt(N)) )
template <class Integer>
constexpr bool IsPrime(const Integer n) noexcept {
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
    for (Integer i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}

using P = pair<int, int>;

int main()
{
    int N, M, Q; cin >> N >> M >> Q;
    vector<int> a(Q), b(Q), c(Q), d(Q);
    rep (i, Q)
        cin >> a[i] >> b[i] >> c[i] >> d[i];

    vector<P> ab(Q);
    rep (i, Q)
    {
        ab[i] = P(a[i], b[i]);
    }

    vector<int> S;
    lint sum = 0;
    rep (i, Q)
    {
        auto it1 = S.find(a[i]);
        auto it2 = S.find(b[i]);
        if ((it1 != S.end()) and (it2 != S.end())){
            sum += d[i];
        }
        else {
            int index1 = distance(S.begin(), it1);
            int index2 = distance(S.begin(), it1);
            if (d[i] > d[index])
            {
                sum -= d[index];
                sum += d[i];
            }
        }
        S.insert(ab[i]);
    }
    
    cout << sum << endl;
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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*n-1
score = int(A*x/B) - A*int(x/B)
if score>max:
    max = score
print(max)

Submission status: Runtime Error

Solution code:
import math

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

ans = list()
for x in range(1,n+1):
    ans.append(int(str(x * a)[0:-1]))

print(max(ans))

Submission status: Runtime Error

Solution code:
result=[]; a,b,n = list(map(int,input().split()))
for x in range(n+1):
  result.append((math.floor(a*x/b))-(a*math.floor(x/b)))
else:
  print(max(result))

Submission status: Runtime Error

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

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m,q=MI()
strs=[[[] for i in range(m)] for i in range(n)]
for i in range(m):
    strs[0][i].append(str(i))
#print(strs)
for i in range(n-1):
    for j in range(m):
        for k in range(j,m):
            for s in strs[i][k]:
                strs[i+1][j].append(str(j)+s)
#print(strs)

L=strs[n-1]
#print(L)
lis=[]
for i in range(m):
    for s in L[i]:
        lis.append(s)
#print(lis)
mx=0
zyou=[LI() for i in range(q)]
for u in lis:
    po=0
    for k in range(q):
        a,b,c,d=zyou[k]
        if int(u[b-1])-int(u[a-1])==c:
            po+=d
    if po>mx:
        mx=po
print(mx)

Submission status: Runtime Error

Solution code:
def main(n,m,q):
    l=[]
    k=10**12
    for i in range(1,q+1):
        k=j
        j=(n*i)//m-n*(i//m)
        if k<j:
            break
    print(max(l))
n,m,q=map(int,input().split())
main(n,m,q)

Submission status: Runtime Error

Solution code:
import math

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

for i in range(A*N/B):
    tmp_ans = math.floor(i) - A*math.floor(i/A)
    if ans < tmp_ans:
        ans = tmp_ans

print(tmp_ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

def main():
  a, b, n = map(int, input().split())
  
  h = 10**12
  
  for x in range(h):
    i = a*x/b
    l = x/b
    
    ans = max(math.floor(i)-a*math.floor(l))
  print(ans)
  
main()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
line = list(map(int,input().split()))
A,B,N =line[0],line[1],line[2]

ans = (N+1)//B
if ans ==0:
    print(math.floor(A*N/B)-A*(i-1))
else:
    start = (math.floor(A*N/B)-A*math.floor(N/B))
    for i in range(1,ans+1):
        x= i*B-1
        start = max((math.floor(A*x/B)-A*(i-1)),start)
    print(start)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if N <B:
	print(math.floor(A*N/B))
	exit()

if N == B:
	print(0)
	exit()

k = [0]*(math.floor(N/B))

for i in range (1, len(k)+1):
	k[i-1] = i*B-1

p=[0]*len(k)

for i in range (0, len(k)):
	p[i] = math.floor(A*k[i]/B)-A*math.floor(k[i]/B)

print(max(p), math.floor(A*N/B)-A*math.floor(N/B))

Submission status: Runtime Error

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

print(floor(A*3/B)-A*floor(3/B))
break

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = 0

if N < B:
    ans = int((A*N)/B))
else:
    n = B//N
    f = 0
    for i in range(n):
        int(A*(N-i)/B)-A*(n-i)
        if f>= ans:
            ans = f
        
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math


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


s = input()
input_arr = s.split()

a = int(input_arr[0])
b = int(input_arr[1])
n = int(input_arr[2])

if a > b:
    if b <= n:
        x_max = b
    else:
        x_max = n

    v = []

    for i in range(x_max):
        v.append(calc(a, b, i+1))

    print(max(v))

else:
    if b <= n:
        x_max = b
    else:
        x_max = n

    x_min = b/a
    x_min = math.floor(x_min)+1

    v = []

    for i in range(x_min, x_max):
        v.append(calc(a, b, i+1))

    print(max(v))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
A,B,N=map(int,input().split())
s=0
for x in range N:
  p=math.floor((A*x)/B)
  q=math.floor(x/B)
  t=A*q
  r=p-t
  if r>s:
    s=r
print(int(s))

Submission status: Runtime Error

Solution code:
from math import floor

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


def floorMax(nums):
    ans = floor((a * nums)/b) - a * floor(nums/b)
    return ans


def findPeakUtil(arr, low, high, n):
    mid = low + (high - low)/2
    mid = int(mid)

    if ((mid == 0 or floorMax(arr[mid-1]) <= floorMax(arr[mid])) and (mid == n - 1 or floorMax(arr[mid + 1]) <= floorMax(arr[mid]))):
        return mid
    elif (mid > 0 and floorMax(arr[mid - 1]) > floorMax(arr[mid])):
        return findPeakUtil(arr, low, (mid - 1), n)
    else:
        return findPeakUtil(arr, (mid + 1), high, n)
def findPeak(arr, n):
    return findPeakUtil(arr, 0, n - 1, n)
li = list(range(0, n+1))
index = findPeak(li, n)
ans = li[index]
print(floorMax(ans+1))

Submission status: Runtime Error

Solution code:
a, b, n = map(int, input().split())
max_int = 0
if a != b:
    if n < b:
        max_int = int((a*n)/b) -a * int(n/b)
    else:
        #for i in range(n, n-max(int(b/a), int(a/b), int(a%b), int(b%a))-1, -1):
        for i in range(i, n):
            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: Runtime Error

Solution code:
import math
A, B, N= map(int, input().split())
for i in range(0, N):
print(floor(A*i/B)-A*floor(i/B))

Submission status: Runtime Error

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


def function(x, a=a, b=b):
    return int(a * x / b) - a * int(x / b)


ans = function(0)
for i in (n):
    if i * b - 1 > n:
        ans = max(ans, function(n))
        break
    ans = max(ans, function(i * b - 1))

print(ans)

Submission status: Runtime Error

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

A, B, N = MAP()

left, right = 0, N

def f(x):
    return int(A*x/B) - A*int(x/B)


# while right-left > 1:
#     mid1 = (left + right)*1// 3
#     mid2 = (left + right)*2// 3

#     if f(mid1) < f(mid2):
#         if left == mid1:
#             break
#         left = mid1
#     else:
#         if right == mid1:
#             break
#         right = mid2

# ans = f(left)
# for i in range(left, right+1):
#     ans = max(ans, f(i))
# print(ans)
# ans = 0
# # whilefor i in range(1, N+1):
# #     ans = max(ans, f(i))
# # print(ans)

# x = N//2
# if f(x) <= f(x)
# direc = "R"

ans = 0
if B > N:
    ans = f(N)
else:
    ans = f(i*B-1)

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math
import numpy as np

# 標準入力の取得
A, B, N = list(map(int, input().split()))

# 求解処理


def func(x: np.ndarray) -> np.ndarray:
    return np.floor(A*x/B) - A*np.floor(x/B)


result = 0
x = np.arange(min(N, B-1), (N//2)+1, B)
x = func(x)
result = max(result, int(np.max(x)))
x = np.arange((N//2), N+1, B)
x = func(x)
result = max(result, int(np.max(x)))


# 結果出力
print(int(np.max(x)))

Submission status: Runtime Error

Solution code:
import math 
a,b,n=map(int,input().split())
def calc(x):
    global a,b
    return math.floor(a*x/b)-a*math.floor(x/b)
bef=-100
count=0
for i in range(1,n+1):
    num=calc(i)
    if num==0:
        if bef!=0:
            if count==0:
                count+=1
            else:
                break
    kind.add(num)
    bef=num
print(bef)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import math

i = 0
lst = []
A, B, N = map(int,input().split())
while(i < N + 1)
    res = math.floor((A*i)/B) - A * math.floor(4/B)
    lst.append(res)
    i += 1

print(max(lst))

Submission status: Runtime Error

Solution code:
n, m, q = map(int, input().strip().split())
L = [list(map(int, input().split())) for _ in range(q)]

possibleA=[[i]*n for i in range(1,m+1)]
for i in range(n):
    for j in range(i+1,m+1):
        

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    import math

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

    if (N >= B):
        syou = N // B
    else:
        syou = 0

    if (syou == N / B):
        a=1
        ## ans = syou * (A - 1) + 1
        # ans = math.floor(A * syou) - A * syou
        # ans = syou * (A - 1)

    else:
        ans = syou * (A - 1)
        mod = N / B - N // B
        y = 1 - mod
        cnt = 0
        for i in range(1, A):
            num = i / A
            if (num > y):
                cnt = A - i
                break
        ans += cnt

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
A,B,N = map(int, input().split())  
ANS=[0]*(N)
k=1
for i in range(N):
  if B<k or A<k:
    break
  ANS[i]=math.floor(A*k/B)-(A*math.floor(k/B))
  k+=1
ANS.sort()
print(ANS[-1])

Submission status: Runtime Error

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

if N <B:
	print(math.floor(A*N/B))
	exit()

if N == B:
	print(0)
	exit()

k = [0]*(math.floor(N/B)+1)

for i in range (1, len(k)+1):
	k[i-1] = i*B-1

k[-1] = N

p=[0]*len(k)

for i in range (0, len(k)):
	p[i] = math.floor(A*k[i]/B)-A*math.floor(k[i]/B)

print(max(p))

Submission status: Runtime Error

Solution code:
def floor(x):
    x=str(x)
    re=""
    for i in range(len(x)):
        if x[i]=='.':
            return int(re)
        re+=x[i]
    return int(re)
a,b,n=map(int,input().split())
ma=0
t=0
for x in range(1,n+1):
    t=floor(a*x/b)
    if t<=ma:
        continue
    t-=a*floor(x/b)
    if ma<t:
        ma=t
print(ma)

Submission status: Runtime Error

Solution code:
A, B, N = [int(x) for x in input().strip().split(" ")]

fs = []
for x in range(N, max(N - B, 0), -1):
    fs.append( (A * x // B) % A)
    if fs[-1] < fs[-2]:
        break
print(max(fs))

Submission status: Runtime Error

Solution code:
import math
import numpy as np

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

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

	if t > ans:
		ans = t

print(ans)

Submission status: Runtime Error

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

for i in range(int(n/4),n+1):
    if b>n:
        lis.append(int(a*n/b))
        break
    if (a*i)%b==0:
        continue
    k = int(a*i/b)-a*int(i/b)
    lis.append(k)
    
print(max(lis))

Submission status: Runtime Error

Solution code:
A, B, N= map(int, input().split())
sys.setrecursionlimit(10**12)
score=[0]*N
for i in range(N):
    score[i]=(A*(i+1)//B)-A*((i+1)//B)
print(max(score))

Submission status: Runtime Error

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

left = 2
right = n

while right - left > 1:
    x = (left + right) // 2
    k = a*x
    l = x//b
    p = a*(x-1)
    q = (x-1)//b
    if (k//b-a*l) > (p//b-a*q):
        left = x
    else:
        right = x

k = a*(x+1)
l = (x+1)//b
s = (k//b-a*l)

print (s)

Submission status: Runtime Error

Solution code:
A,B,N= list(map(int, input().split()))
ma=0
for i in range(min(N,B)+1,1):
    a=int(A*i/B)-A*int(i/B)
    if(a<=A):
    	if(ma<a):
        	ma=a
            break
print(ma)

Submission status: Runtime Error

Solution code:
a, b , n = map(int, input().split())
def floor_abx(a, b, x):
    return int(a*x/b) - int(x/b)*a 
    
res = 0

for i in range(n+1-a*(a%abs(a-b) +1), n+1):
    num = floor_abx(a, b, i)
    if res < num:
        res = num

print(res)

Submission status: Runtime Error

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

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

A,B,N = [int(hoge) for hoge in input().split()]
G = math.gcd(A,B)
Old_A = copy.deepcopy(A)
if not A%B:#AがBの倍数:
    x = min(B-1,N)
    print((Old_A*x)//B - Old_A * (x//B))
    exit()
A = A//G
if A%B:
    invA = mod_inv(A,B)
else:invA = 0

if B == 1:
    print(0)
    exit()
else:
    InvList = []
    if A == 1:
        InvList.append((0,N,Old_A//B))
    for i in range(min(Old_A,B)+1):
        #Ax=i(modB)なので、x = i*(inv_A) mod B
        if i:
            amari = (i * invA)%B #候補のx mod B

        else:amari = 0# Ax mod B=0 のとき、x mod B = 0
        x = N - N%B + amari
        if x > N :
            x-=B
        x -= 1
        axx = (amari,x,(Old_A*x)//B - Old_A * (x//B))
        if x < 0:continue
        InvList.append(axx)
    InvList.append((0,N,(Old_A*N)//B - Old_A * (N//B)))
    InvList.sort(key = lambda x:x[2],reverse=True)
    print(InvList[0][2])

Submission status: Runtime Error

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

if N <B:
	print(math.floor(A*N/B))
	exit()

k = [0]*(math.floor(N/B)+1)

for i in range (1, len(k)+1):
	k[i-1] = i*B-1

k[-1] = N

p=[0]*len(k)

for i in range (0, len(k)):
	p[i] = math.floor(A*k[i]/B)-A*math.floor(k[i]/B)

print(max(p))

Submission status: Runtime Error

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

A, B, N = MAP()

left, right = 0, N

def f(x):
    return int(A*x/B) - A*int(x/B)


# while right-left > 1:
#     mid1 = (left + right)*1// 3
#     mid2 = (left + right)*2// 3

#     if f(mid1) < f(mid2):
#         if left == mid1:
#             break
#         left = mid1
#     else:
#         if right == mid1:
#             break
#         right = mid2

# ans = f(left)
# for i in range(left, right+1):
#     ans = max(ans, f(i))
# print(ans)
# ans = 0
# # whilefor i in range(1, N+1):
# #     ans = max(ans, f(i))
# # print(ans)

# x = N//2
# if f(x) <= f(x)
# direc = "R"

ans = 0
if B > N:
    ans = f(N)
else:
    f(i*B-1)

print(ans)

Submission status: Runtime Error

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

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

import math


if __name__ == '__main__':
    a, b, n = map(int, input().split())
    if b > n:
        return print(n)
    else:
        return print(b - 1)

Submission status: Runtime Error

Solution code:
A, B, N= map(int, input().split())
sys.setrecursionlimit(10**6)
score=[0]*N
for i in range(N):
    score[i]=(A*(i+1)//B)-A*((i+1)//B)
print(max(score))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import sys
import math

sys.setrecursionlimit(10 ** 6)

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


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


def trisect(func):
    left = 1
    right = n
    while abs(right - left) > 0.001:
        d = right - left
        mid_left = left + d / 3
        mid_right = right - d / 3
        if func(mid_left) < func(mid_right):
            left = mid_left
        elif func(mid_left) > func(mid_right):
            right = mid_right
        else:
            return left
    return left


x = trisect(func)
# print(x)
print(max(func(math.floor(x)), func(math.ceil(x), func(1), func(n))))

Submission status: Runtime Error

Solution code:
A = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
i_max = 0
i_count = 0
j_count = 0
h_count = 0

for x in range(1, A[2]+1):
  if i_max < ((A[0]*x)//A[1]-A[0]*(x//A[1])):
    i_max = ((A[0]*x)//A[1]-A[0]*(x//A[1]))
    i_count = x
  if i_max = ((A[0]*x)//A[1]-A[0]*(x//A[1])):
    j_count = x
  if (i_count != 0) and (j_count != x):
    break
    
print(i_count)

Submission status: Runtime Error

Solution code:
import sys
import heapq
input = sys.stdin.readline
A,B,N=map(int,input().split())
Z=[0]*(N+1)
if A<=B:
    for x in range(N+1):
        Y=int(A*x/B)-A*int(x/B)
        Z[x]=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: Runtime Error

Solution code:
import math
A, B, N = map(int, input().split())
# xはN以下
# int(A*x/B) - A*int(x/B)の最大値を求めたい


compute_range = list(range(0, math.ceil(N / B) + 1))
# print(compute_range)


def h(x):
    return int(int((A * x) / B) - A * int(x / B))


max_num = max(h(N), h(N % B))
print(max_num)

Submission status: Runtime Error

Solution code:
a, b , n = map(int, input().split())
def floor_abx(a, b, x):
    return int(a*x/b) - int(x/b)*a 
    
res = 0
def
for i in range(n+1-a*(a%abs(a-b) +1), n+1):
    num = floor_abx(a, b, i)
    if res < num:
        res = num

print(res)

Submission status: Runtime Error

Solution code:
from math import floor
A,B,N = map(int,input().split())
cnt = 0
siki = 0
if A == 0 :
    cnt = 0
elif B / A == int(B / A) :
    for i in range(B/A) :
        siki = floor(A*i/B) - A * floor(i/B)
        cnt = max(siki,cnt)
elif B < N :
    for i in range(B) :
        siki = floor(A*i/B) - A * floor(i/B)
        cnt = max(siki,cnt)
else :
    cnt = floor(A*N/B) - A*floor(N/B)

print(cnt)

Submission status: Runtime Error

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

import sys

def keisan(A,B,N):
  	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

	return int(max)

print(keisan(A,B,N))

Submission status: Runtime Error

Solution code:
from math import floor
a, b, n = list(map(int, input().split()))
def floorMax(nums):
    ans = floor((a * nums)/b) - a * floor(nums/b)
    return ans
def findPeakUtil(arr, low, high, n):
    mid = low + (high - low)/2
    mid = int(mid)

    if ((mid == 0 or floorMax(arr[mid-1]) <= floorMax(arr[mid])) and (mid == n - 1 or floorMax(arr[mid + 1]) <= floorMax(arr[mid]))):
        return mid
    elif (mid > 0 and floorMax(arr[mid - 1]) > floorMax(arr[mid])):
        return findPeakUtil(arr, low, (mid - 1), n)
    else:
        return findPeakUtil(arr, (mid + 1), high, n)
def findPeak(arr, n):
    return findPeakUtil(arr, 0, n - 1, n)
index = findPeak(list(range(0, n+1)), n)
ans = list(range(n))[index]
print(floorMax(ans+1))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
A,B,N=map(int,input().split())
s=0
for x in range N:
  p=math.floor(A*x/B)
  q=A*math.floor(x/B)
  r=p-q
  if r>s:
    s=r
print(int(s))

Submission status: Runtime Error

Solution code:
a, b, n = list(map(int, input().split()))
x, ans = 1, 0
while True:
	if ans < int(a * x / b) - a * int(x / b):
      ans = int(a * x / b) - a * int(x / b)
    else:
      print(x)
      break
    x += 1

Submission status: Runtime Error

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(B):
        m = A * x % B
        if m >= 1:
            mods.append(m)
    
    # 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: Runtime Error

Solution code:
import math
from decimal import Decimal
a,b,n = map(int,input().split())
ans = 0
al = []
    
for i in range(n,-1,-1):
    t = Decimal(str(a))*Decimal(str(i))//Decimal(str(b))
    t2 = Decimal(str(a))*(Decimal(str(i))//Decimal(str(b)))
    ans = t-t2
    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: Runtime Error

Solution code:
import math
A, B, N = map(int, input().split())
 
if N <B:
	print(math.floor(A*N/B))
	exit()
 
k = [0]*(math.floor(N/B)+1)
 
for i in range (1, len(k)+1):
	k[i-1] = i*B-1
 
k[-1] = N
 
p=[0]*len(k)
 
for i in range (0, len(k)):
	p[i] = math.floor(A*k[i]/B)-A*math.floor(k[i]/B)
 
print(max(p))

Submission status: Runtime Error

Solution code:
A,B,N = list(map(int,input().split()))
if N <= 10000:
    C = [A*i//B-(A*(i//B)) for i in range(0,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),max(E)))

Submission status: Runtime Error

Solution code:
import numpy as np
a, b, n = map(int, input().split())
x = np.arange(1, b+1)
y = np.floor(a * x / b) - a * np.floor(x / b)
print(y)
print(int(y.max()))

Submission status: Runtime Error

Solution code:
def f(A,B,x):
    return (((A*x)//B)-(A*(x//B)))
def main():
    A,B,N=map(int,input().split())
    lb=1
    ub=min(B-1,N)
    while(lb<=ub):
        mid=(lb+ub)//2
        if f(A,B,mid)<N:
            lb=mid+1
        elif f(A,B,mid)>N:
            ub=mid-1
        else:
            break
    print(f(A,B,mid))
if __name__=='__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

import sys

def keisan(A,B,N):
    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
    
    return int(max)

print(keisan(A,B,N))

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def floor(x):
    x=str(x)
    re=""
    for i in range(len(x)):
        if x[i]=='.':
            return int(re)
        re+=x[i]
a,b,n=map(int,input().split())
ma=0
t=0
for x in range(1,n+1):
    t=floor(a*x/b)
    if t<=ma:
        continue
    t-=a*floor(x/b)
    if ma<t:
        ma=t
print(ma)

Submission status: Runtime Error

Solution code:
a,b,n = map(int,input().split())
if a == 1 or b == 1:
    print(0)
    exit()

prev = 0

for x in range(min(b-1,n),n+1, b):
    val = floor(a*x/b) - a*floor(x/b)
    if val < prev:
        print(prev)
        exit()
    prev = val

val = floor(a*n/b) - a*floor(n/b)
print(max(prev,val))

Submission status: Runtime Error

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

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

A,B,N = [int(hoge) for hoge in input().split()]
G = math.gcd(A,B)
Old_A = copy.deepcopy(A)
if not A%B:#AがBの倍数:
    x = min(B-1,N)
    print((Old_A*x)//B - Old_A * (x//B))
    exit()
A = A//G
if A%B:
    invA = mod_inv(A,B)
else:invA = 0

if B == 1:
    print(0)
else:
    InvList = []
    if A == 1:
        InvList.append((0,N,Old_A//B))
    for i in range(min(Old_A,B)+1):
        #Ax=i(modB)なので、x = i*(inv_A) mod B
        if i:
            amari = (i * invA)%B #候補のx mod B

        else:amari = 0# Ax mod B=0 のとき、x mod B = 0
        x = N - N%B + amari
        if x > N :
            x-=B
        x -= 1
        axx = (amari,x,(Old_A*x)//B - Old_A * (x//B))
        if x < 0:continue
        InvList.append(axx)
    InvList.append((0,N,(Old_A*N)//B - Old_A * (N//B)))
    InvList.sort(key = lambda x:x[2],reverse=True)
    print(InvList[0][2])

Submission status: Runtime Error

Solution code:
from math import floor
A,B,N = map(int,input().split())
cnt = 0
siki = 0
if B / A == int(B / A) :
    for i in range(B/A) :
        siki = floor(A*i/B) - A * floor(i/B)
        cnt = max(siki,cnt)
elif B < N :
    for i in range(B) :
        siki = floor(A*i/B) - A * floor(i/B)
        cnt = max(siki,cnt)
else :
    cnt = floor(A*N/B) - A*floor(N/B)

print(cnt)

Submission status: Runtime Error

Solution code:

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

if N%2 ==0:
  print(N/2)
 else:
  print(N)