#P6889. Graph Theory Class

    ID: 5746 远端评测题 7000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2020中国大学生程序设计竞赛(CCPC) - 网络选拔赛

Graph Theory Class

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$.

3 3 998244353 100 998244353 1000000000 998244353
10 6307 192026508