The 2022 ICPC Asia Xian Regional Contest--C. Clone Ranran

Ranran needs to prepare a contest! A contest is made of c problems, and Ranran can do one of the following two things:

  • Clone himself in a minutes. That is, after a minutes, there will be one more Ranran.
  • Prepare a problem in b minutes. That is, after b minutes, there will be one more problem.

Note that a cloned Ranran can also do the two things above. A Ranran cannot do the two things at the same time.

Ranran wants to prepare the contest as fast as possible. But he is very lazy, so he asks you to find the minimum number of minutes to prepare the contest.

You need to answer T queries independently.

Input

The first line contains an integer T (1≤T≤10^5).

Each of the next T lines contains three integers aa, bb and cc (1≤a,b,c≤109), representing a query.

Output

For each test case, output a line with a single integer representing the answer.

Example

input

5
1 1 1
2 3 3
9 9 9
3 26 47
1064 822 1048576

output

1
7
45
44
21860

题意:主人公初始有0个题目,可以花a分钟克隆自己,可以花b分钟使每个自己创造1个题目,问创造c个题目的最小耗时。

解析:可以发现,克隆自己是2的幂次,可以推出,如果需要克隆N次,那么先克隆N次,最后再操作2肯定是最合理的,因此我们可以枚举克隆的次数,因为是指数,所以最多才31次(因为c最大10的9次)

#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
void solve()
{
	ll a,b,c,r=1,minn=1e15;//最小值初始化要大一点
	scanf("%lld%lld%lld",&a,&b,&c);
	for(int i=0;i<32;i++)//克隆i次
	{
		minn=min(minn,i*a+((c-1)/r+1)*b);//更新答案
		r*=2;
	}
	printf("%lld\n",minn);
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--) solve();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值