#P5364. [SNOI2017] 礼物
[SNOI2017] 礼物
Description
The hospitable little monkey invites friends from the forest to dinner. His friends are numbered from to . Each arriving friend will bring him some gifts: big bananas.
The first friend brings big banana. After that, when each friend arrives, they will bring the total number of gifts brought by all previous friends, plus their own index raised to the -th power.
So, if , the numbers of gifts brought by the first few friends are:
If , the numbers of gifts brought by the first few friends are:
Now, the little monkey is curious about how many gifts he will receive from the -th friend, so he asks for your help.
Given and , output the number of gifts brought by the -th friend modulo .
Input Format
The first line contains two integers .
Output Format
Output one integer, representing the number of gifts brought by the -th friend modulo .
4 2
37
2333333 2
514898185
1234567890000 3
891659731
66666666 10
32306309
Hint
- of the testdata: .
- Another of the testdata: .
- Another of the testdata: .
- Another of the testdata: .
- of the testdata: , .
Translated by ChatGPT 5
京公网安备 11011102002149号