|
||||||||||
Graph Theory ClassTime Limit: 14000/7000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 3331 Accepted Submission(s): 859 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
Sample Output
Source | ||||||||||
|