CodeChef: June Challenge | Bella ciao | CHFHEIST | Python, Java C++ Solution

Codechef

Chef is planning a heist in the reserve bank of Chefland. They are planning to hijack the bank for DD days and print the money. The initial rate of printing the currency is PP dollars per day and they increase the production by QQ dollars after every interval of dd days. For example, after dd days the rate is P+QP+Q dollars per day, and after 2d2d days the rate is P+2QP+2Q dollars per day, and so on. Output the amount of money they will be able to print in the given period.

For the work from home Internship Programs : Click here to apply now

Input

  • The first line contains an integer TT, the number of test cases. Then the test cases follow.
  • Each test case contains a single line of input, four integers D,d,P,QD,d,P,Q.

Output

For each test case, output in a single line the answer to the problem.

Constraints

  • 1≤T≤1051≤T≤105
  • 1≤d≤D≤1061≤d≤D≤106
  • 1≤P,Q≤1061≤P,Q≤106

Subtasks

Subtask #1 (15 points): d≤D≤100d≤D≤100

Subtask #2 (85 points): original constraints

Sample Input

3
2 1 1 1
3 2 1 1
5 2 1 2

Sample Output

3
4
13

Explanation

Test Case 1:

  • On the first day, the rate of production is 11 dollar per day so 11 dollar is printed on the first day.
  • On the second day, the rate of production is 1+1=21+1=2 dollars per day so 22 dollars are printed on the second day.
  • The total amount of money printed in 22 days is 1+2=31+2=3 dollars.

Test Case 2:

  • For the first two days, the rate of production is 11 dollar per day so 1⋅2=21⋅2=2 dollars are printed on the first two days.
  • On the third day, the rate of production is 1+1=21+1=2 dollars per day so 22 dollars are printed on the third day.
  • The total amount of money printed in 33 days is 2+2=42+2=4 dollars.

Test Case 3:

  • For the first two days, the rate of production is 11 dollar per day so 1⋅2=21⋅2=2 dollars are printed on the first two days.
  • On the next two days, the rate of production is 1+2=31+2=3 dollars per day so 3⋅2=63⋅2=6 dollars are printed on the next two days.
  • On the last day, the rate of production is 3+2=53+2=5 dollars per day so 55 dollars are printed on the last day.
  • The total amount of money printed in 55 days is 2+6+5=132+6+5=13 dollars.

Solution

Due to copyright issues we won't be able to update the solution here immediately. However you can download the code file from our telegram channel. So join our telegram channel for further updates. Keep tracking, the solution will be updated on this website soon.
  • HACKEREARTH IS HIRING FOR INTERN || APPLY NOW
  • INTEL IS HIRING FOR SOFTWARE DEVELOPER INTERN || APPLY Now
  • DATA SCIENCE INTERNSHIP | SONY RESEARCH INDIA || APPLY NOW

Read more post Here

Leave a Comment

Your email address will not be published. Required fields are marked *

x