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

Graph Theory Class

Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 3167    Accepted Submission(s): 827


Problem Description
This class is on graph theory. Mr. Kruskal teaches babies the concept of minimal spanning tree, and how to calculate the minimal spanning tree of a given graph.

Now, it's time for an in-class quizz. Mr. Kruskal shows a special graph $G$: $G$ is a complete undirected graph with $n$ vertices, and vertices in $G$ are indexed from $1$ to $n$. The weight of the edge between the $i$th vertex and the $j$th vertex is equal to $lcm(i+1,j+1)$. Babies are asked to find the minimal spanning tree of $G$.

As a super baby, Baby Volcano quickly finds an answer, but he is not sure on the correctness of his answer. Your task is to tell Baby Volcano the weight sum of all edges on the minimal spanning tree, so that he could verify his answer.

Given two positive integers, $lcm(i,j)$ is defined as the minimal positive integer $k$ satisfying both $i$ and $j$ are factors of $k$.
 

Input
The first line contains a single integer $t (1 \leq t \leq 50)$, the number of testcases.

For each testcase, the first line contains two integers $n, K (1 \leq n \leq 10^{10}, 10^8 \leq K \leq 10^9)$.

The input guarantees that $K$ is a prime number.

The input guarantees that there are no more than $5$ testcases with $n > 10^9$.
 

Output
For each testcase, output a single line with a single integer, the answer module $K$.
 

Sample Input
3 3 998244353 100 998244353 1000000000 998244353
 

Sample Output
10 6307 192026508
 

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-03 18:57:29, Gzip enabled