Medium Math > Probability/Expected Value

Interestingly the probability of winning 1st prize in the lottery is higher than the probability of winning 10th prize, if you don't win the any prize from 2nd to 10th. Minas buys a lottery ticket and he knows **N** people buy lottery including him. He knows a magic trick, which he can use to win a lottery prize. But he can only use the magic if the winning probability is greater than or equal to **P**. When prize giving is occurring, people getting the prize and his winning probability are getting higher and when his winning probability is greater than or equal to **P**, he does the magic and win a prize. Now he will give you the number of people buying the lottery is **N** and probability is **P**. You need to tell minimum number of prize organizer needs to declare so that Minas can use his magic trick to win a prize. Input: ------ Input starts with an integer **T (1<=T<=100000)**, denoting the number of test cases. Each case contains an integer **N** denoting the number of people buy lottery ticket and **p** and **q** where **p/q = P**. **1 ≤ N, p, q ≤ 1000000000** **0 < p/q <= 1** Output: ------- For each case of input, output the minimum number of prize need to declare so that he can use his magic trick to win a prize. Sample Input ------------ 2 1 1 1 3 1 2 Sample Output ------------- 1 2

MD Musfiqur Rahman Sanim