Responsive image

问题 1804 --If the starlight never fade

1804: If the starlight never fade

时间限制: 2 Sec  内存限制: 128 MB
提交: 0  解决: 0
[提交][状态][讨论版][命题人:]

题目描述

We will give you a non-negative integer m and a prime number p. 
And we define f(i) is the number of pair(x,y) that satisfies (x+y)i≡xi%p and 1≤x≤p−1,1≤y≤m.
Now, you have to calculate the sum ∑p−1i=1if(i). 
Maybe the sum is too big,so you only need to output the sum after mod 1e9+7.
 

输入描述

The first line contains only one integer T, which indicates the number of test cases. 
For each test case, there are a integer m(1≤m≤p−1) and a prime number p(2≤p≤1e9+7) on one line. 

输出描述

For each test case, output one line "Case #x: y", where x is the case number (starting from 1) and y is the sum after mod 1e9+7.

样例输入

3
5 7
3 11
2 103

样例输出

Case #1: 210
Case #2: 390
Case #3: 50388

来源

 

[提交][状态]
ACM算法攻关部