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

HeHe

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1948    Accepted Submission(s): 640


Problem Description
In the equation X^2¡ÔX(mod N) where x¡Ê[0,N-1], we define He[N] as the number of solutions.
And furthermore, define HeHe[N]=He[1]*¡­¡­*He[N]
Now here is the problem, write a program, output HeHe[N] modulo M for a given pair N, M.
 

Input
First line: an integer t, representing t test cases.
Each test case contains two numbers N (1<=N<=10^7) and M (0<M<=10^9) separated by a space.
 

Output
For each test case, output one line, including one integer: HeHe[N] mod m.
 

Sample Input
1 2 3
 

Sample Output
2
 

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-11-21 20:32:03, Gzip enabled