8656: Shortest Path in GCD Graph

内存限制:128 MB 时间限制:5 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

There is an edge-weighted complete graph Kn with nn vertices, where vertices are labeled through 1,2,...,n. For each 1i<jn, the weight of the edge (i,j) between i and j is gcd(i,j), the greatest common divisor of i and j.

You need to answer q queries. In each query, given two vertices u,v, you need to answer the length of the shortest path as well as the number of shortest paths between u,v. Since the number of shortest paths may be too large, you only need to output it modulo 998244353

输入格式

The first line contains two integers n,q(2n107,1q50000), denoting the number vertices in the graph and the number of queries, respectively.

Then q lines follow, where each line contains two integers u,v(1u,vn,u!=v), denoting a query between u and v.

输出格式

For each query, output one line contains two integers, denote the length and number of shortest path between given nodes, respectively. Note that only the number of shortest paths should be taken modulo 998244353

输入样例 复制

6 2
4 5
3 6

输出样例 复制

1 1
2 2