In the problem Guess it Right, won't the given problem form a GP(geometric progression).
Consider if the given number of moves are odd:
In the first step play will guess, and then in the next step, he will remove those 'k' boxes which were added in the first step. This will continue till player reaches 'M' number of moves.
Let m=5;k=23;n=3
The probability will be:
P=1/3+(2/3)*(1/3)+(2/3)*(2/3)*(1/3)
This forms a GP.
Similarly, we can do the same for even numbers, only one extra fraction will be added.
Let m=6;k=23;n=3
P=(1/3)+(2/3)*(1/3)+(2/3)*(2/3)*(1/3)+(2/3)*(2/3)*(2/3)*(1/26)
Again we will get a GP(excluding the last term).
I used this logic to solve the problem, what's wrong in this?
Edit: I have corrected the first term in the odd case and the last term in the even case. My code for the solution using python is given in comment section.
Yes you are right, it will form a GP. But in the examples which you gave, the first term will be 1/3 i.e. 1/n and not 2/3.
Also, the last fraction in last term in the case of even m will be 1/26 i.e. 1/(n+k) instead of 1/23 (i.e. 1/k) . Rest all seems fine.
Your First term is Wrong it should be 1/3 and Multiplication of these big numbers will be too large as the constraint is of 3*10^4
So better u generate a general formula for that GP which is (n)^p-(n-1)^p where p is (m/2)+1 and use power function with mod which will not take that much time
Did the same still got WA
Can somebody find error in my code https://www.codechef.com/viewsolution/23050669
and you don’t even have to consider GP sum(though both are same) its simply 1-P(right guess never happens)
if m is odd and earlier term +P(right guess never happens)*(1/(n+k))if m is even
Yes, your approach seems fine.
If CHEF has more than 1 move then he will first remove boxes then he will choose one box. This leads to a GP \frac{1}{n} + (1- \frac{1}{n})*\frac{1}{n}+(1- \frac{1}{n})^2*\frac{1}{n}+....
If m is odd then GP would have \frac {m}{2} terms. If m is even then still GP would have same \frac {m}{2} terms and also a last term would be {(1- \frac{1}{n})}^{m/2}*\frac{1}{n+k}. So summation of this GP is the answer.
If m is ODD then answer is \frac{1}{n} + (1- \frac{1}{n})*\frac{1}{n}+(1- \frac{1}{n})^2*\frac{1}{n}+...+{(1- \frac{1}{n})}^{m/2}*\frac{1}{n}
Else (m is EVEN) answer is \frac{1}{n} + (1- \frac{1}{n})*\frac{1}{n}+(1- \frac{1}{n})^2*\frac{1}{n}+...+{(1- \frac{1}{n})}^{m/2-1}*\frac{1}{n} + {(1- \frac{1}{n})}^{m/2}*\frac{1}{n+k}
May be you are doing wrong while calculating powers. Also whenever you perform subtraction operation, you should always add MOD and then take MOD. For example if you write ans -= x; then ans = MOD. In this case you may get negative answer is x > ans. So you should do ans -=x; ans += MOD; ans %= MOD;