VENOM - Touch of Venom

no tags 

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


hide comments
Baojun Wang: 2015-07-01 03:13:40

just i/o, impossible for most languages except c/c++ for current time limit.

Last edit: 2015-08-01 09:27:15
Nikhil Arya: 2015-06-27 21:08:15

my 50th

Apoorva: 2015-06-23 15:08:11

Write it down and observe the pattern. Formula can easily be derived then.

kp: 2015-06-20 07:35:39

fast i/o + O(1) + basic math ... classic spoj :)

---@@@----: 2015-05-20 19:35:59

huh....... !!!!!!

ASHUTOSH DWIVEDI: 2015-05-14 19:18:18

time limit is very strict but good us of maths......AC after unlimited TLEs
my 50th

Last edit: 2015-05-14 19:19:05
:.Mohib.:: 2015-05-09 05:01:18

Really enjoyed it.....awsm que..... AC :)

LUCIFER: 2015-03-30 20:15:32

In python 2.7.9 there are problems in importing math module as it is giving NZEC.Plz check code with id 13988915...code is giving correct answer on ideone

Last edit: 2015-03-31 07:39:42
Aman Sachan: 2015-01-22 21:38:32

Try to find out O(1) solution. And also use scanf, printf instead of cin, cout..
It caused me 4 TLE.. :)

One_touch_finish: 2015-01-21 22:41:25

@thewatch my ac code prints 3 for 4 2 0


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