#P8229. [AGM 2022 资格赛] 抛硬币
[AGM 2022 资格赛] 抛硬币
Problem Description
Yili found a magic number , a magic basket full of strawberries, and a magic coin.
Yili noticed that when flipping the coin, it has a probability of to land heads up. Then she flips the coin times. If the coin lands heads up, the strawberries in the basket become times the original amount. Otherwise, she will eat all the strawberries in the basket. After she finishes eating, the basket will magically produce one new strawberry.
Yili is now curious about the expected number of strawberries she will eat after flipping the coin times. Please tell her the answer modulo .
Input Format
The first line contains an integer , indicating the number of test cases.
The next lines each contain three integers .
Output Format
Output lines. Each line contains a positive integer representing the answer.
4
1 2 499122177
3 2 499122177
10 2 499122177
1000000000000000000 100 16235235
499122177
748683267
748683281
565383148
Hint
Constraints
For of the testdata, it holds that , , and .
Notes
Translated from AGM 2022 Qualification Round A CoinFlip。
Translated by ChatGPT 5