A. Vasya and Chocolate

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jj12345jj198999/article/details/83240563

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a special offer in Vasya's favourite supermarket: if the customer buys aa chocolate bars, he or she may take bb additional bars for free. This special offer can be used any number of times.

Vasya currently has ss roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs cc roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!

Input

The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of testcases.

Each of the next tt lines contains four integers s,a,b,c (1≤s,a,b,c≤109)s,a,b,c (1≤s,a,b,c≤109) — the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.

Output

Print tt lines. ii-th line should contain the maximum possible number of chocolate bars Vasya can get in ii-th test.

Example

input

Copy

2
10 3 1 1
1000000000 1 1000000000 1

output

Copy

13
1000000001000000000

Note

In the first test of the example Vasya can buy 99 bars, get 33 for free, buy another bar, and so he will get 1313 bars.

In the second test Vasya buys 10000000001000000000 bars and gets 10000000000000000001000000000000000000 for free. So he has 10000000010000000001000000001000000000 bars.

解题说明:水题,按照题目要求进行求解即可。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	long long t = 0, s = 0, c = 0, a = 0, b = 0, i = 0, j = 0, p = 0, q = 0, r = 0;
	scanf("%lld", &t);
	for (i = 0; i<t; i++)
	{
		scanf("%lld%lld%lld%lld", &s, &a, &b, &c);
		p = s / c;
		q = (p / a)*b;
		r = p + q;
		printf("%lld\n", r);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/jj12345jj198999/article/details/83240563