Educational Codeforces Round 52 (Rated for Div. 2) A. Vasya and Chocolate

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

A. Vasya and Chocolate

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

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

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

Each of the next t lines contains four integers 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 t lines. i-th line should contain the maximum possible number of chocolate bars Vasya can get in i-th test.

Example
inputCopy

2
10 3 1 1
1000000000 1 1000000000 1
outputCopy
13
1000000001000000000
Note
In the first test of the example Vasya can buy 9 bars, get 3 for free, buy another bar, and so he will get 13 bars.

In the second test Vasya buys 1000000000 bars and gets 1000000000000000000 for free. So he has 1000000001000000000 bars.
水题

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int t ;
	long long s,a,b,p,ans=0;
	scanf("%d",&t);
	while(t--)
	{
	
	cin>>s>>a>>b>>p;
	ans=s/p+(s/p)/a*b;
	cout<<ans<<endl;
	
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/u011469138/article/details/83722350
今日推荐