AtCoder Beginner Contest 165 - Floor Function

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-----
5 7 4

-----Sample Output-----
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.

Difficulty: MEDIUM_HARD

Starter code:

Solutions:
(a, b, n) = map(int, input().split())
k = max(0, (n - b + 1) // b)
k = min(n, k * b + b - 1)
print(a * k // b - a * (k // b))


from math import floor

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


(a, b, n) = map(int, input().split())
print(a * min(n, b - 1) // b)


(A, B, N) = map(int, input().split())
x = min(N, B - 1)
print(int(A * x / B))


from math import *
(A, B, N) = map(int, input().split())
print(floor(A * min(N, B - 1) / B))


(A, B, N) = list(map(int, input().split()))
import math
if B - 1 < N:
	print(math.floor(A * (B - 1) / B) - A * math.floor((B - 1) / B))
else:
	print(math.floor(A * N / B) - A * math.floor(N / B))


(A, B, N) = map(int, input().split())
c = min(N, B - 1)
print(str(int(A * c / B) - A * int(c / B)))


(A, B, N) = [int(_) for _ in input().split()]
i = min(N, B - 1)
ans = A * i // B - A * (i // B)
print(ans)


def f(a, b, n):
	if b == 1:
		print(0)
	else:
		Max = 0
		step = 1 if b // a == 0 else b // a
		for x in range(b // a, n + step, step):
			res = a * x // b - a * (x // b)
			if res > Max:
				Max = res
		print(Max)
(a, b, n) = list(map(int, input().split()))
f(a, b, n)


(a, b, n) = map(int, input().split())
x = min(b - 1, n)
ans = a * x // b
print(ans)


(A, B, N) = list(map(int, input().split()))
if B <= N:
	a = int(A * (B - 1) / B)
	b = 0
	print(max(a, b))
else:
	a = int(A * N / B)
	b = 0
	print(max(a, b))


def main():
	(A, B, N) = map(int, input().split())
	x = min(B - 1, N)
	ans = A * x // B - A * (x // B)
	print(ans)

def __starting_point():
	main()
__starting_point()


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


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


(A, B, N) = list(map(int, input().split()))
if N >= B:
	N = B - 1
print(A * N // B)


(a, b, n) = map(int, input().split())
x = max(1, min(b - 1, n))
print(int(a * x / b) - a * int(x / b))


(A, B, N) = map(int, input().split())
r = min(B - 1, N)
print(A * r // B)


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

def f(x):
	return int(A * x / B) - A * int(x / B)
print(f(min(B - 1, N)))


(a, b, n) = list(map(int, input().split()))
i = min(n, b - 1)
print(a * i // b)


import numpy as np
(A, B, N) = map(int, input().split())
if B <= N:
	x = B - 1
	print(int(np.floor(A * x / B)))
else:
	print(int(np.floor(A * N / B)))


(N, M, K) = map(int, input().split())
print(N * min(M - 1, K) // M)


(A, B, N) = list(map(int, input().strip().split()))
print(A * min(B - 1, N) // B)


(a, b, n) = map(int, input().split())
i = min(b - 1, n)
ans = a * i // b - a * (i // b)
print(ans)


(A, B, N) = list(map(int, input().split()))
num = min(B - 1, N)
print(num * A // B)


import sys
from collections import deque, Counter, defaultdict
import bisect
import heapq
import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
inf = 10 ** 18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
mod = 998244353
(a, b, n) = rl()
if n / b >= 1:
	print(math.floor(a * (b - 1) / b))
else:
	print(math.floor(a * n / b))


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

def f(a, b, x):
	return a * x // b - a * (x // b)
print(f(a, b, min(b - 1, n)))


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


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


(a, b, n) = list(map(int, input().split()))
print(int((a * min([b - 1, n]) + 0.01) / b))


import math

def __starting_point():
	(a, b, n) = list(map(int, input().split()))
	ans = 0
	lp = min(b - 1, n)
	ans = math.floor(a * lp / b) - a * math.floor(lp / b)
	print(ans)
__starting_point()


(a, b, n) = map(int, input().split())
x = b - 1
if n < b - 1:
	x = n
r = a * x // b
print(r)


(A, B, N) = map(int, input().split())
if B > N:
	print(A * N // B)
else:
	print(A * (B - 1) // B)


from math import floor
(a, b, n) = map(int, input().split())
x = min(b - 1, n)
print(floor(a * x / b) - a * floor(x / b))


(a, b, n) = map(int, input().split())
m = 0
x = min(n, b - 1)
r = x // b
d = x / b - r
print(int(a * d))


(A, B, N) = map(int, input().split())
n = min(B - 1, N)
print(A * n // B)


def main():
	import sys
	pin = sys.stdin.readline
	pout = sys.stdout.write
	perr = sys.stderr.write
	(A, B, N) = list(map(int, pin().split()))
	x = min(B - 1, N)
	ans = int(A * x / B) - A * int(x / B)
	print(ans)
	return
main()


(A, B, N) = map(int, input().split())
X = min(B - 1, N)
print(A * X // B)


(A, B, N) = map(int, input().split())
i = min(B - 1, N)
print(A * i // B - A * (i // B))


def main():
	(a, b, n) = map(int, input().split(' '))
	x = min(b - 1, n)
	print(a * x // b - a * (x // b))

def __starting_point():
	main()
__starting_point()


import sys
from itertools import chain

def solve(A: int, B: int, N: int):
	if N >= B:
		x2 = B - 1
	else:
		x2 = N
	return A * x2 // B

def main():
	tokens = chain(*(line.split() for line in sys.stdin))
	A = int(next(tokens))
	B = int(next(tokens))
	N = int(next(tokens))
	answer = solve(A, B, N)
	print(answer)

def __starting_point():
	main()
__starting_point()


import math
(a, b, n) = map(int, input().split())
d = min(b - 1, n)
print(math.floor(a * d / b) - a * math.floor(d / b))


import numpy as np
(a, b, n) = map(int, input().split())
if b - 1 <= n:
	value = np.floor(a * (b - 1) / b) - a * np.floor((b - 1) / b)
else:
	value = np.floor(a * n / b) - a * np.floor(n / b)
print(int(value))


(a, b, n) = map(int, input().split())
f = lambda x: a * x // b - a * (x // b)
print(f(min(b - 1, n)))


(a, b, c) = map(int, input().split())
print(a * min(b - 1, c) // b)


(A, B, N) = map(int, input().split())
from decimal import Decimal
A = Decimal(A)
B = Decimal(B)
i = min(B - 1, N)
print(int(A * i / B) - A * (i // B))


(A, B, N) = map(int, input().split())
C = min(N, B - 1)
print(int(C * A / B))


(A, B, N) = [int(i) for i in input().split()]
t = min([N, B - 1])
print(A * t // B)


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


def delete_head_zeros(n):
	n = str(n)
	l = len(n)
	if '.' in n:
		l = n.find('.')
	head_zeros = 0
	for i in range(l - 1):
		if n[i] == '0':
			head_zeros += 1
		else:
			break
	return n[head_zeros:]

def bigint_compare(a, b):
	a = delete_head_zeros(a)
	b = delete_head_zeros(b)
	if len(a) > len(b):
		return 1
	elif len(a) < len(b):
		return -1
	elif a > b:
		return 1
	elif a < b:
		return -1
	else:
		return 0

def bigint_plus(a, b):
	a = str(a)
	b = str(b)
	d = max([len(a), len(b)])
	a = '0' * (d - len(a)) + a
	b = '0' * (d - len(b)) + b
	ans = ''
	carry = 0
	for i in range(d):
		s = int(a[-i - 1]) + int(b[-i - 1]) + carry
		carry = s // 10
		ans = str(s % 10) + ans
	else:
		if carry:
			ans = str(carry) + ans
	return ans

def bigint_minus(a, b):
	a = str(a)
	b = str(b)
	M = []
	m = []
	sign = ''
	if len(a) > len(b) or (len(a) == len(b) and a >= b):
		[M, m] = [a, b]
	else:
		[M, m] = [b, a]
		sign = '-'
	m = '0' * (len(M) - len(m)) + m
	ans = ''
	borrow = 0
	for i in range(len(M)):
		s = int(M[-i - 1]) - int(m[-i - 1]) - borrow
		if s < 0:
			borrow = 1
			s += 10
		else:
			borrow = 0
		ans = str(s) + ans
	return sign + delete_head_zeros(ans)

def bigint_multiply(a, b):
	a = str(a)
	b = str(b)
	md = []
	for j in range(len(b)):
		carry = 0
		mj = ''
		for i in range(len(a)):
			m = int(a[-i - 1]) * int(b[-j - 1]) + carry
			carry = m // 10
			mj = str(m % 10) + mj
		else:
			if carry:
				mj = str(carry) + mj
		md.append(mj)
	ans = 0
	for k in range(len(md)):
		ans = bigint_plus(md[k] + '0' * k, ans)
	return ans

def bigint_divide(a, b, d=0):
	a = str(a)
	b = str(b)
	d = int(d)
	if d < 0:
		d = 0
	ans = ''
	r = ''
	for i in range(len(a) + d):
		q = 0
		if i < len(a):
			r += a[i]
		elif i == len(a):
			ans += '.'
			r += '0'
		else:
			r += '0'
		if bigint_compare(r, b) == -1:
			ans += str(q)
		else:
			while bigint_compare(r, b) >= 0:
				r = bigint_minus(r, b)
				q += 1
			ans += str(q)
	return delete_head_zeros(ans)

def main():
	(A, B, N) = [int(x) for x in input().split(' ')]
	r = min([N, B - 1])
	print(bigint_divide(bigint_multiply(A, r), B))
main()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, bisect
import sys
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
stdin = sys.stdin
ni = lambda : int(ns())
nf = lambda : float(ns())
na = lambda : list(map(int, stdin.readline().split()))
nb = lambda : list(map(float, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
(A, B, N) = na()
if N >= B - 1:
	print(math.floor(A * (B - 1) / B) - A * math.floor((B - 1) / B))
else:
	print(math.floor(A * N / B) - A * math.floor(N / B))


(a, b, n) = map(int, input().split())
x = min(b - 1, n) * 1.0
print(int(1.0 * a * x / b) - a * int(1.0 * x / b))


(a, b, n) = list(map(int, input().split()))
if b > n:
	x = n
else:
	x = b - 1
ans = int(a * x / b)
print(ans)


(A, B, N) = (int(_) for _ in input().split())
x = min(N, B - 1)
print(A * x // B)


(A, B, N) = map(int, input().split())
m = min(B - 1, N)
print(int(A * (m / B)))


(A, B, N) = map(int, input().split())
f = lambda x: int(A * x / B) - A * int(x / B)
print((A > 1) * (B > 1) * f(min(N, B - 1)))


(A, B, N) = map(int, input().split())
ans = A * min(N, B - 1) // B
print(ans)


(a, b, n) = map(int, input().split())
temp = min(n, b - 1)
ans = int(a / b * temp)
print(ans)


(A, B, N) = map(int, input().split())
min = N
if N > B - 1:
	min = B - 1
print(A * min // B - A * (min // B))


import math

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

def main(A, B, N):
	if N < B:
		return f(A, B, N)
	else:
		return f(A, B, B - 1)
(A, B, N) = list(map(int, input().split()))
print(main(A, B, N))


import sys

def input():
	return sys.stdin.readline().rstrip()

def main():
	(a, b, n) = map(int, input().split())
	if b <= n:
		n = b - 1
	print(a * n // b - a * (n // b))

def __starting_point():
	main()
__starting_point()


(A, B, N) = map(int, input().split())
x = 0
if B > N:
	x = N
else:
	x = B - 1
print(A * x // B)


(A, B, N) = [int(x) for x in input().split()]
Q = A // B
R = A % B
if R == 0:
	ans = Q * (B - 1)
elif B <= N:
	ans = R - 1 + Q * (B - 1)
else:
	ans = int(A * N / B) - A * int(N / B)
print(ans)


(A, B, N) = map(int, input().split())
max = int(A * min(B - 1, N) / B)
print(max)


import math
ini = lambda : int(input())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
gcd = lambda x, y: gcd(y, x % y) if x % y else y

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
		if temp % i == 0:
			cnt = 0
			while temp % i == 0:
				cnt += 1
				temp //= i
			arr.append([i, cnt])
	if temp != 1:
		arr.append([temp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors

class UnionFind:

	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n

	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return
		if self.parents[x] > self.parents[y]:
			(x, y) = (y, x)
		self.parents[x] += self.parents[y]
		self.parents[y] = x

	def size(self, x):
		return -self.parents[self.find(x)]

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def members(self, x):
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i) == root]

	def roots(self):
		return [i for (i, x) in enumerate(self.parents) if x < 0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()}

	def __str__(self):
		return '\n'.join(('{}: {}'.format(r, self.members(r)) for r in self.roots()))
mod = 10 ** 9 + 7
(a, b, n) = inm()
ans = 0
x = min(b - 1, n)
ans = max(ans, a * x // b - a * (x // b))
print(ans)


import math
(A, B, N) = map(int, input().split())
if N < B:
	temp1 = math.floor(A * 1 / B) - A * math.floor(1 / B)
	temp2 = math.floor(A * N / B) - A * math.floor(N / B)
	ans = max(temp1, temp2)
if N >= B:
	temp1 = math.floor(A * 1 / B) - A * math.floor(1 / B)
	temp2 = math.floor(A * (B - 1) / B) - A * math.floor((B - 1) / B)
	ans = max(temp1, temp2)
print(ans)


(a, b, n) = list(map(int, input().split()))
k = n if n < b else b - 1
print(int(a * k) // b)


(a, b, n) = map(int, input().split())
x = min(n, b - 1)
l = a * x // b
r = a * (x // b)
print(l - r)


(A, B, N) = list(map(int, input().split()))
s = min(N, B - 1)
print(A * s // B - A * (s // B))


(A, B, N) = map(int, input().split())
if N >= B - 1:
	i = B - 1
	ans = A * i // B - A * (i // B)
else:
	ans = A * N // B - A * (N // B)
print(ans)


from math import floor
(A, B, N) = map(int, input().split())
f = lambda x: floor(A * x / B) - A * floor(x / B)
if A == 1 or B == 1:
	print(0)
	return
if N < B:
	print(f(N))
	return
print(f(B - 1))


(A, B, N) = [int(n) for n in input().split()]
print(int(A * min(N, B - 1) / B))


(A, B, N) = list(map(int, input().split()))
x = min(N, B - 1)
ans = A * x // B
print(ans)


(A, B, N) = map(int, input().split())
if B == 1:
	print(0)
	return
if N <= B:
	print(max(A * (N - 1) // B - A * ((N - 1) // B), A * N // B - A * (N // B)))
else:
	print(A - 1)


from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
(a, b, n) = readInts()
th = b - 1
if n >= th:
	print(int(math.floor(a * th / b) - a * math.floor(th / b)))
else:
	print(int(math.floor(a * n / b) - a * math.floor(n / b)))


import bisect, collections, copy, itertools, math, string
import sys

def I():
	return int(sys.stdin.readline().rstrip())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def S():
	return sys.stdin.readline().rstrip()

def LS():
	return list(sys.stdin.readline().rstrip().split())

def main():
	(a, b, n) = LI()
	ans = 0

	def f(a, b, x):
		ans = a * x // b - a * (x // b)
		return ans
	if b - 1 <= n:
		ans = f(a, b, b - 1)
	else:
		ans = f(a, b, n)
	print(ans)
main()


(A, B, N) = map(int, input().split())
k = min(B - 1, N)
print(int(A * k / B))


(A, B, N) = map(int, input().split())
mn = min(B - 1, N)
mx = int(A * mn / B)
print(mx)


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


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


(a, b, n) = map(int, input().split())
x = min(n, b - 1)
s = a * x // b - a * (x // b)
print(s)


def f(x):
	return int(x)
from decimal import Decimal
(A, B, N) = list(map(int, input().split()))
ans = 0
if N >= B:
	X = [1, B - 1, N]
else:
	X = [1, N]
for x in X:
	if x == B:
		culc = 0
	elif x < B:
		culc = f(A * Decimal(x / B))
	else:
		culc = f(A * Decimal(x / B)) - A * f(Decimal(x / B))
	if culc > ans:
		ans = culc
print(ans)


(A, B, N) = map(int, input().split())
if N >= B:
	N -= N % B + 1
f = A * N // B
g = A * (N // B)
print(f - g)


(A, B, N) = map(int, input().split())
a = min(N, B - 1)
print(A * a // B)


(a, b, N) = [int(x) for x in input().split()]
print(a * min(b - 1, N) // b)


(a, b, n) = map(int, input().split())
x = b - 1
if x > n:
	x = n
p = a * x // b
q = x // b
print(p - q)


[A, B, N] = [int(i) for i in input().split()]
u = 0
s = float('inf')
if B - 1 <= N:
	t = A * (B - 1) // B - A * ((B - 1) // B)
else:
	u += 1
if 2 * B - 1 <= N:
	s = A * (2 * B - 1) // B - A * ((2 * B - 1) // B)
else:
	u += 1
print(min(s, t) if u != 2 else A * N // B - A * (N // B))


import math
import collections
import itertools
import copy

def YesNo(Bool):
	if Bool:
		print('YES')
	else:
		print('NO')
	return

def resolve():
	(A, B, N) = list(map(int, input().split()))
	X = min(N, B - 1)
	ans = math.floor(A * X / B)
	print(ans)
resolve()


(A, B, N) = list(map(int, input().split()))
ans = 0
if N < B:
	ans = int(A * N / B) - A * int(N / B)
elif N == B:
	ans = int(A * (N - 1) / B) - A * int((N - 1) / B)
else:
	ans = int(A * (B - 1) / B) - A * int((B - 1) / B)
print(ans)


(a, b, n) = map(int, input().split())
if b == 1:
	print(0)
	return
else:
	x = min(b - 1, n)
	ans = a * x // b - a * (x // b)
print(ans)


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
(a, b, n) = [int(i) for i in input().split()]
tmp = 0
res = 0
for x in range(min(b, n), -1, -1):
	res = floor(a * x / b) - a * floor(x / b)
	if res > 0:
		break
print(res)


def solve(A, B, N):
	x = min(B - 1, N)
	a = A * x // B - A * (x // B)
	return a
(A, B, N) = list(map(int, input().split()))
print(solve(A, B, N))


(A, B, N) = map(int, input().split())
temp = min(N, B - 1)
print(int(A / B * temp))


(A, B, N) = map(int, input().split())
t = min(B - 1, N)
print(int(A * t / B) - A * int(t / B))


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


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


import math
(A, B, N) = list(map(int, input().split()))
x = min(B - 1, N)
print(math.floor(A * x / B))


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


import math
import sys
input = sys.stdin.readline

def main():
	(A, B, N) = map(int, input().split())
	x = min(B - 1, N)
	print(math.floor(A * x / B) - A * math.floor(x / B))
main()


def abc165d_floor_function():
	(a, b, n) = map(int, input().split())
	i = min(n, b - 1)
	max_val = a * i // b - a * (i // b)
	print(max_val)
abc165d_floor_function()