Input
In the first line of input, there is one integer t (1≤t≤10e4) denoting the number of test cases.
Each of the following t lines describes one test case and contains three integers n, k, g (1≤n≤10e9 1≤≤109, 0≤k≤10e9 , 2≤g≤10e9 ) — respectively the number of astrophysicists in the company, total number of gold coins to assign and the number of silver coins that one gold coin corresponds to.
Output
In a separate line for each test case, output a single integer — the maximum number of silver coins that could be saved due to rounding.
n==物理学家人数,k==金币数量,g==转化概率;
四舍五入程序如下。如果天体物理学家的奖金等于 x银币,我们表示 r=x mod g, 然后:
- 如果 r≥⌈g/2⌉, 天体物理学家收到 x+(g−r)银币;
- 否则,天体物理学家会收到 x−r银币。
- 当 g=10时 g/2==5;即四舍五入;
最后献上图图姐姐代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
void solve()
{
int t;
cin>>t;
while(t--)
{
ll n,k,g;
cin>>n>>k>>g;
ll ans=(g-1)/2*n;
ans=min(ans/g,k);
cout<<ans*g<<'\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}