DIVEQL - The Magical Bag
Dukkar has the magical bag of power 'P' . Here power 'P' of magical bag means any thing kept in the bag will be 'P' times.
Now Dukkar wanted to distribute equal number of Chocolates among his 'N' students using that magical bag in the following manner:-
Initially Dukkar has 'Z' chocolates and he give 'X' chocolates to first student and keep the remaining chocolates to magical bag so that it became 'P' times on next step ,again he will take out 'X' chocolates from bag and give it to the second student and the remaining chocolates in the bag at this step will get 'P' time on the next step ,this process continue.
Here you have to find minimum 'Z' so that at last step there are no chocolates in the magical bag (After giving 'X' chocolates to last student no chocolates should remain in bag)
First line of input contain T (<100000) number of test cases and the following T lines will contain N (2<=N<=1018) and P (2<=P<=109).
For each test case you have to print minimum 'Z' and corresponding 'X' .As answer can be large print answer modulo 1000000007.
(Z%1000000007 and X % 1000000007)
As Z=7 ,Initially dukkar will give 4 chocolates to first student and kepp 3 chocolates in bag .In the
next step it became 6 now he gives 4 chocolates to second student .In the next step remaining 2
chocolates will be came 4 which he will give to third student .Now the bag became empty.
Just consider Gcd and try to prove why it will be 1.
easy one...no tricky cases
Raghav Aggiwal Again:
Forgetting a newline at the end of output caused me 7 wa.. :(
NZEC error , please check my submission
Vamsi Krishna Avula:
Nishant Raj sir, can you please tell me why code is getting NZEC? ID: 13260236
giving TLE please help
AC in a go :)
@Nishant, c u check #11955896, #11955817