# Calculator

## 题目描述

Chef has a calculator which has two screens and two buttons. Initially, each screen shows the number zero. Pressing the first button increments the number on the first screen by $1$, and each click of the first button consumes $1$ unit of energy.
Pressing the second button increases the number on the second screen by the number which is currently appearing on the first screen. Each click of the second button consumes $B$ units of energy.
Initially the calculator has $N$ units of energy.
Now chef wonders what the maximum possible number is, that he gets on the second screen of the calculator, with the limited energy.

## 代码

#include <iostream>
#include <cmath>
using namespace std;
long long T, n, b, p, q, x, ans;
long double k;
int main()
{
cin >> T;
while (T--) {
cin >> n >> b;
ans = 0;
k = 1.0 * n / 2 / b;
p = floor(k), q = ceil(k);
x = n - b * p;
if (x > 0 && x < n) ans = max(ans, p * x);
x = n - b * q;
if (x > 0 && x < n) ans = max(ans, q * x);
cout << ans << endl;
}
return 0;
}


418 I'm a teapot