AT4827 [ABC165D] Floor Function题解

题面

思路

我们观察减数,小学数学老师教过:减数越小,差越大。

因此,我们考虑使 \(a \times \left \lfloor \frac{x}{b} \right \rfloor\) 最小。

小学数学老师还教过:任何数乘零都得零,发现我们只要使 \(b<x\) 就可以使 \(\left \lfloor \frac{x}{b} \right \rfloor\) 得到零。

所以 \(b<x\)

所以最大的重任来到 $\left \lfloor \frac{ax}{b} \right \rfloor $ 上——无脑开大啊,因此 \(b\) 要是小于 \(x\) 的最大整数,因题目限制 \(x\) 取值于 $ [ 1,n ] $,所以 \(x=\max(n,b-1)\)

题目答案就是 $\left \lfloor \frac{ax}{b} \right \rfloor \(,其中 x 值也得到,\)O(1)$ 可得结果。

Code

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	int a,b,n;
	cin>>a>>b>>n;
	cout<<a*min(n,b-1)/b;
	return 0;
}

posted @ 2022-02-16 17:29  ㅤSmartBig  阅读(102)  评论(0)    收藏  举报