F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

If the starlight never fade

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 361    Accepted Submission(s): 209


Problem Description
We will give you a non-negative integer $m$ and a prime number $p$.
And we define $f\left(i\right)$ is the number of pair$\left(x,y\right)$ that satisfies $\left(x + y\right) ^ {i} \equiv x ^ {i} \% p$ and $1 \leq x \leq p - 1,1 \leq y \leq m$.
Now, you have to calculate the sum $\sum_{i=1}^{p-1}if\left(i\right)$.
Maybe the sum is too big,so you only need to output the sum after mod $1e9+7$.
 

Input
The first line contains only one integer $T$, which indicates the number of test cases.
For each test case, there are a integer $m \left(1 \leq m \leq p - 1 \right)$ and a prime number $p\left(2 \leq p \leq 1e9 + 7 \right)$ on one line.
 

Output
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$.
 

Sample Input
3 5 7 3 11 2 103
 

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

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-18 19:06:36, Gzip enabled