Your company was appointed to lay new asphalt on the highway of length nn. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.
Skipping the repair is necessary because of the climate. The climate in your region is periodical: there are gg days when the weather is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next bb days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again gg good days, bb bad days and so on.
You can be sure that you start repairing at the start of a good season, in other words, days 1,2,…,g are good.
You don't really care about the quality of the highway, you just want to make sure that at least half of the highway will have high-quality pavement. For example, if the n=5 then at least 3 units of the highway should have high quality; if n=4n=4 then at least 22 units should have high quality.
What is the minimum number of days is needed to finish the repair of the whole highway?
The first line contains a single integer T (1≤T≤104) — the number of test cases.
Next TT lines contain test cases — one per line. Each line contains three integers nn, gg and bb (1≤n,g,b≤1091≤n,g,b≤109) — the length of the highway and the number of good and bad days respectively.
Print TT integers — one per test case. For each test case, print the minimum number of days required to repair the whole highway if at least half of it should have high quality.
3
5 1 1
8 10 10
1000000 1 1000000
5
8
499999500000
Note
In the first test case, you can just lay new asphalt each day, since days 1,3,5are good.
In the second test case, you can also lay new asphalt each day, since days 1-8 are good.
给定一个长度为n的路,连续的有g天好天气和b天坏天气,在好天气的情况下能修出好的路,坏天气则不能,要求输出最小的完成天数且满足n/2向上取整的长度为好的路。为了满足n/2向上取整的长度为好的路,可以选择在坏天气的时候休息。并且工作天数至少要有n天。计算天数有两种情况,当n/2向上取整对g取余等于0的时候,就是sum=(g+b)*(day/g)-b,如果不为0则是sum=(g+b)*(day/g)+day%g。
#include
#include
#include
#include
using namespace std;
int main()
{
int t;
scanf("%d",&t);
long long n,g,b;
while(t--)
{
scanf("%lld%lld%lld",&n,&g,&b);
long long day=(n+1)/2;//好的路
long long sum=0;
if(day%g==0)//如果一半好的路不能和好天气整除的话,说明要加上好的路对好的天气取余,
sum=(g+b)*(day/g)-b;//如果好的路能和好天气整除的话,因为是好天气在前面,所以应减去最后一个坏天气
else
sum=(g+b)*(day/g)+day%g;//得出的结果要大于n天,如果小于n的话是不对的
printf("%lld\n",max(sum,n));
}
return 0;
}