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

Root

Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 977    Accepted Submission(s): 271


Problem Description
Given a number $sum(1\leq sum \leq 100000000)$,we have $m$ queries which contains a pair ($x_i,y_i$) and would like to know the smallest nonnegative integer $k_{i}$ satisfying $x_i^{k_{i}}=y_i\ mod\ p$ when the prime number $p\ (sum\ mod\ p = 0)$(ps:$0^0=1$)
 

Input
The first line contains a number T, indicating the number of test cases.

For each case, each case contains two integers $sum,m(1\leq sum\leq 100000000,1\leq m\leq 100000)$ in the first line.

The next $m$ lines will contains two intgeers $x_i,y_i(0\leq x_i,y_i\leq1000000000)$
 

Output
For each test case,output "Case #$X$:" and $m$ lines.($X$ is the case number)

Each line cotain a integer which is the smallest integer for ($x_i,y_i$) ,if we can't find such a integer just output "-1" without quote.
 

Sample Input
1 175 2 2 1 2 3
 

Sample Output
Case #1: 0 3
 

Hint

$175\ =5^2*7$

$2^0\ mod\ 5\ =\ 1$

$2^3\ mod\ 7\ =\ 1$

So the answer to (2,1) is 0
 

Author
UESTC
 

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-04-27 08:11:52, Gzip enabled