Array ( [0] => [1] => questions [2] => Codevita-Previous-Questions [3] => Death-Battle ) Codevita Previous Questions | Death Battle | THE INQUISITIVE





Death Battle

LEVEL:Beginner

Description

In a crossover fantasy universe, Houin Kyoma is up in a battle against a powerful monster Nomu that can kill him in a single blow. However being a brilliant scientist Kyoma found a way to pause time for exactly M seconds. Each second, Kyoma attacks Nomu with certain power, which will reduce his health points by that exact power. Initially Nomu has H Health Points. Nomu dies when his Health Points reach 0. Normally Kyoma performs Normal Attack with power A. Besides from Kyomas brilliance, luck plays a major role in events of this universe. Kyomas Luck L is defined as probability of performing a super attack. A super attack increases power of Normal Attack by C. Given this information calculate and print the probability that Kyoma kills Nomu and survives. If Kyoma dies print "RIP.

Input Format

First line is integer T denoting number of test cases.

Each test case consist of single line with space separated numbers A H L1 L2 M C. Where luck L is defined as L1/L2. Other numbers are, as described above.

Output Format

Print probability that Kyoma kills Nomu in form P1/P2 where P1<=P2 and gcd(P1,P2)=1. If impossible, print "RIP without quotes.


Example 1:

Input
2
10 33 7 10 3 2
10 999 7 10 3 2
Output
98/125
RIP
Example 2:

Input
3
12 56 6 10 4 3
10 46 7 10 4 2
15 100 3 10 6 5
Output
108/625
1029/5000
495369/1250000
Example 3:

Input
4
23 156 9 10 6 5
14 106 7 10 10 2
35 100 3 10 2 5
Output
45927/250000
1/1
RIP

oops

Login to see Discussion




Approach

Step-i)first import math and fractions module
Step-ii)create a method gcd to find gcd of two numbers
Step-iii)create a method comb which takes n and r as argument
Step-iv)assign 1 to p and k
Step-v)if n- r is less than r update n to n-r
Step-vi)if r is less than 0
Step-vii)while r is greater than 0 follow below step
Step-viii) update p to p*n , k to k*n , m to gcd of (p,k) , p to p//m, k to k//m and decrement values of n and r
Step-ix)else update p to 1
Step-x)return p
Step-xi)create a method result which takes a,h,l1,l2,m,c as argument
Step-xii)assign l1/l2 to l
Step-xiii)assign h-m*a to remain_health
Step-xiv)assing min_sup = ceil of (remain_health/c)
Step-xv)update p to Fraction(0,1)
Step-xvi)update x to comb(m,min_sup-1)
Step-xvii)for i in range of min_sup to m+1 follow below step
Step-xviii)assing Fraction((x*(m-i)),i) to x and update p to p+x*(Fraction(l1,l2)*i)((Fraction(1,1)-Fraction(l1,l2))**(m-i))
Step-xix) if min_sup is greater than m return "RIPelse return P
Step-xx)in main method take the neccessary inputs and print the output


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution