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

GuGuFishtion

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2615    Accepted Submission(s): 924


Problem Description
Today XianYu is too busy with his homework, but the boring GuGu is still disturbing him!!!!!!
At the break time, an evil idea arises in XianYu's mind.
¡®Come on, you xxxxxxx little guy.¡¯
¡®I will give you a function $\phi(x)$ which counts the positive integers up to $x$ that are relatively prime to $x$.¡¯
¡®And now I give you a fishtion, which named GuGu Fishtion, in memory of a great guy named XianYu and a disturbing and pitiful guy GuGu who will be cooked without solving my problem in 5 hours.¡¯
¡®The given fishtion is defined as follow:
$$G_u (a,b)=\frac{\phi(ab)}{\phi(a)\phi(b)}$$
And now you, the xxxxxxx little guy, have to solve the problem below given $m$,$n$,$p$.¡¯
$$(\sum\limits_{a=1}^m\sum\limits_{b=1}^nG_u (a,b))\pmod p$$
So SMART and KINDHEARTED you are, so could you please help GuGu to solve this problem?
¡®GU GU!¡¯ GuGu thanks.
 

Input
Input contains an integer $T$ indicating the number of cases, followed by $T$ lines. Each line contains three integers $m$,$n$,$p$ as described above.
$1\le T\le 3$
$1\le m,n\le 1,000,000$
$\max(m,n)<p\le 1,000,000,007$
And given $p$ is a prime.
 

Output
Please output exactly $T$ lines and each line contains only one integer representing the answer.
 

Sample Input
1 5 7 23
 

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-22 10:03:20, Gzip enabled