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. Here is the link: https://www.codechef.com/JULY17/problems/CALC/
Contest is ended, so I am not trying to cheat. here is my solution to the problem:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,b;
cin>>n>>b;
int count = 1;
int ans = n-b;
while((n - count*b)>=0)
{
if(count*(n - count*b)>ans)
ans = count*(n - count*b);
count++;
}
cout<<ans<<endl;
}
return 0;
}
I have tried every test case that i can think of... Can anyone help to find the error in my logic.