CF1334E.Divisor Paths

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a positive integer DD . Let's build the following graph from it:

  • each vertex is a divisor of DD (not necessarily prime, 11 and DD itself are also included);
  • two vertices xx and yy ( x>yx > y ) have an undirected edge between them if xx is divisible by yy and xy\frac x y is a prime;
  • the weight of an edge is the number of divisors of xx that are not divisors of yy .

For example, here is the graph for D=12D=12 :

Edge (4,12)(4,12) has weight 33 because 1212 has divisors [1,2,3,4,6,12][1,2,3,4,6,12] and 44 has divisors [1,2,4][1,2,4] . Thus, there are 33 divisors of 1212 that are not divisors of 44[3,6,12][3,6,12] .

There is no edge between 33 and 22 because 33 is not divisible by 22 . There is no edge between 1212 and 33 because 123=4\frac{12}{3}=4 is not a prime.

Let the length of the path between some vertices vv and uu in the graph be the total weight of edges on it. For example, path [(1,2),(2,6),(6,12),(12,4),(4,2),(2,6)][(1, 2), (2, 6), (6, 12), (12, 4), (4, 2), (2, 6)] has length 1+2+2+3+1+2=111+2+2+3+1+2=11 . The empty path has length 00 .

So the shortest path between two vertices vv and uu is the path that has the minimal possible length.

Two paths aa and bb are different if there is either a different number of edges in them or there is a position ii such that aia_i and bib_i are different edges.

You are given qq queries of the following form:

  • vv uu — calculate the number of the shortest paths between vertices vv and uu .

The answer for each query might be large so print it modulo 998244353998244353 .

输入格式

The first line contains a single integer DD ( 1D10151 \le D \le 10^{15} ) — the number the graph is built from.

The second line contains a single integer qq ( 1q31051 \le q \le 3 \cdot 10^5 ) — the number of queries.

Each of the next qq lines contains two integers vv and uu ( 1v,uD1 \le v, u \le D ). It is guaranteed that DD is divisible by both vv and uu (both vv and uu are divisors of DD ).

输出格式

Print qq integers — for each query output the number of the shortest paths between the two given vertices modulo 998244353998244353 .

输入输出样例

  • 输入#1

    12
    3
    4 4
    12 1
    3 4

    输出#1

    1
    3
    1
  • 输入#2

    1
    1
    1 1

    输出#2

    1
  • 输入#3

    288807105787200
    4
    46 482955026400
    12556830686400 897
    414 12556830686400
    4443186242880 325

    输出#3

    547558588
    277147129
    457421435
    702277623

说明/提示

In the first example:

  • The first query is only the empty path — length 00 ;
  • The second query are paths [(12,4),(4,2),(2,1)][(12, 4), (4, 2), (2, 1)] (length 3+1+1=53+1+1=5 ), [(12,6),(6,2),(2,1)][(12, 6), (6, 2), (2, 1)] (length 2+2+1=52+2+1=5 ) and [(12,6),(6,3),(3,1)][(12, 6), (6, 3), (3, 1)] (length 2+2+1=52+2+1=5 ).
  • The third query is only the path [(3,1),(1,2),(2,4)][(3, 1), (1, 2), (2, 4)] (length 1+1+1=31+1+1=3 ).
首页