VENOM - Touch of Venom

Sometimes you have to try fighting even though you know that your enemy is very powerful than you. Your hero with initial health H is about to fight against a venomous enemy who has a poisonous value of P. The enemy's poison deals i*P damage at it's ith attacking chance(i>=1). The hero dies when his health becomes <=0. After enemy's attack, if the hero survives, he heals himself with a health of A by using his skills. Then the enemy gets the chance again and the cycle continues till the hero dies. Find the survival time of the hero. You can safely assume that the hero is mortal.

Example Scenario:

Initial Health(H) = 10, Poison (P) = 2, Heal value(A) = 1

At time 1, enemy does 1*2 damage reducing the hero's health to 8

At time 2, hero heals himself by 1 increasing his health to 9

At time 3, enemy does 2*2 damage reducing the hero's health to 5

At time 4, hero heals himself by 1 increasing his health to 6

At time 5, enemy does 3*2 damage and kill the hero.

The hero survived 5 units of time.

Input:

The first line consists of an integer t, the number of test cases. For each test case there is a line with 3 integers H, P and A.

Output:

For each test case, find the survival time of the hero.

Input Constraints:

1<=t<=10^6

1<=H<=10^6

1<=P<=10^6

0<=A<P

Sample Input:

3

3 7 2

81 4 1

87 8 4

Sample Output:

1

13

9


Added by:cegprakash
Date:2014-03-10
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: BF

hide comments
2015-01-13 08:58:52 Anubhav Balodhi
Do we have to add 1 second for "the corner case" ?
Aaaah, AC after some mistakes like not checking signs. [edit] v3n0m :-p

Last edit: 2015-01-16 17:28:08
2014-09-29 11:53:38 Pushkar Naik
i got an AC in 1.22 secs. how is this possible considering the time limit is 0.75? @cegprakash

Reply : 0.75 is the time limit for one test file.

Last edit: 2014-11-17 12:37:25
2014-08-22 09:32:02 thewatch
for input => 4 2 0
is the ans 2 or 3
2014-06-30 06:27:57 sarelfeniel
Phew, after a lot of work, was able to get a really good time :D Fantastically fun problem.
2014-06-26 23:37:35 P_Quantum
Nice one!! AC in 0.28 :P
2014-06-26 20:07:21 Samar Holkar
Nice Math...
2014-06-26 12:05:36 [Lakshman]
@Rajeev Kumar why not 13, try this with pen and paper.
2014-06-26 12:02:09 Rajeev Kumar
how ans is 13 for 81 4 1

Last edit: 2014-06-26 12:03:26
2014-06-26 01:35:06 Petar Bosnjak
nice question , think mathematically
2014-06-25 15:00:30 Sandeep Garhwar
for case (15 5 0), is answer 3 or 5
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.