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
tanvirrahmedd: 2022-09-13 13:00:41

[spoiler] + [spoiler]

Last edit: 2023-09-08 16:30:22
satish18: 2019-01-20 06:33:21

my 25th

nadstratosfer: 2018-11-29 13:03:19

Happy to get AC? Now write a bruteforce and see if your solution gives same result for [spoiler]. I don't understand why my AC one doesn't. I love cegprakash's problems but this one wrecked the day for me :(

[cegprakash] : Hi I've added this test case. I understand that a quality problem should include the worst test case. Unfortunately I can't rejudge this problem as there are lot of submissions. But the future solutions will be tested for this case. :)

Last edit: 2019-01-05 12:10:30
kaushalag29: 2018-06-29 12:23:13

TLE with ios_base.Use scanf/printf...

mag1x_: 2018-05-29 15:06:58

Pure math and scanf/printf :)

manmeet_rana: 2017-07-16 15:43:59

did using [spoiler]
hint: [spoiler] is enough and use [spoiler]
ac in 2nd go

Last edit: 2017-08-02 12:46:47
praney_rai: 2017-06-15 11:33:04

did it using [spoiler] :P

Last edit: 2017-08-02 12:47:17
cipher_: 2016-11-03 20:13:27

Nice application of Quadratic sequence. :) <3
Be aware about data type..it might make u get TLE. :)

Last edit: 2016-11-03 21:01:46
aditya_rev: 2016-10-30 04:08:32

carefull with data type, it might make u get tle :)

dwij28: 2015-12-26 09:20:01

AC but 1.23 seconds with scanf and 0.8 with a rather fast input function .. :/ Used inequations, not sure what I can do to decrease time, other than fast I/O .. Wonder how people got O(1) .. Anyways, cegprakash always brings good questions ..

Last edit: 2015-12-28 05:23:55

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