1065A Vasya and Chocolate

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

题目

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≤1000000000) — 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

``
input
2
10 3 1 1
1000000000 1 1000000000 1
output
13
1000000001000000000

``
题意:Vasya买巧克力棒有优惠活动,Vasya每次买a个巧克力棒,可以免费获得b个巧克力棒,每个巧克力棒c元,求Vasya最大能获得多少根巧克力棒。

import java.util.Scanner;

public class VasyaandChocolate {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n-->0)
		{
			long s,a,b,c,ans=0;
			s=sc.nextLong();
			a =sc.nextLong();
			b=sc.nextLong();
			c=sc.nextLong();
			long l =s/c;
			if(l<a)
			{
				ans = l;
			}
			else {
				ans = l/a*b+l;
			}
			System.out.println(ans);
		}
		sc.close();
	}

}

猜你喜欢

转载自blog.csdn.net/z16160102042/article/details/83278498