1065A 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≤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(); } }