CF1334E.Divisor Paths

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

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 \gt 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.

给你一个正整数 DD。我们从它构造如下图:

  • 每个顶点是 DD 的一个约数(不一定是质数,11 和 DD 本身也包含在内);
  • 两个顶点 xx 和 yy(其中 x>yx > y)之间存在一条无向边,当且仅当 xx 被 yy 整除,且 xy\frac{x}{y} 是一个质数;
  • 边的权重定义为:xx 的约数中不是 yy 的约数的个数。

例如,下图是 D=12D = 12 对应的图:

边 (4,12)(4,12) 的权重为 33,因为 1212 的约数为 [1,2,3,4,6,12][1,2,3,4,6,12],而 44 的约数为 [1,2,4][1,2,4],因此 1212 的约数中不属于 44 的约数有 33 个——即 [3,6,12][3,6,12]。

顶点 33 和 22 之间没有边,因为 33 不被 22 整除;顶点 1212 和 33 之间也没有边,因为 123=4\frac{12}{3} = 4 不是质数。

定义图中某两个顶点 vv 和 uu 之间一条路径的长度为该路径上所有边的权重之和。例如,路径 [(1,2),(2,6),(6,12),(12,4),(4,2),(2,6)][(1, 2), (2, 6), (6, 12), (12, 4), (4, 2), (2, 6)] 的长度为 1+2+2+3+1+2=111+2+2+3+1+2 = 11。空路径的长度为 00。

因此,顶点 vv 和 uu 之间的最短路径是指所有路径中长度最小者。

若两条路径 aa 和 bb 满足以下任一条件,则称它们不同:

  • 它们包含的边数不同;
  • 存在某个位置 ii,使得 aia_i 和 bib_i 表示不同的边。

你将收到 qq 个如下形式的查询:

  • vv uu —— 计算顶点 vv 和 uu 之间最短路径的条数。

每个查询的答案可能很大,请对 998244353998244353 取模后输出。

输入格式

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

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

Each of the next qq lines contains two integers vv and uu (1≤v,u≤D1 \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).

第一行包含一个整数 DD(1≤D≤10151 \le D \le 10^{15})—— 图所基于的数。

第二行包含一个整数 qq(1≤q≤3⋅1051 \le q \le 3 \cdot 10^5)—— 查询次数。

接下来的 qq 行中,每行包含两个整数 vv 和 uu(1≤v,u≤D1 \le v, u \le D)。保证 DD 同时被 vv 和 uu 整除(即 vv 和 uu 均为 DD 的约数)。

输出格式

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

输出 qq 个整数——对每个查询,输出两个给定顶点之间最短路径的数量对 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).

在第一个例子中:

  • 第一个查询仅包含空路径——长度为 00;
  • 第二个查询包含路径 [(12,4),(4,2),(2,1)][(12, 4), (4, 2), (2, 1)](长度 3+1+1=53+1+1=5)、[(12,6),(6,2),(2,1)][(12, 6), (6, 2), (2, 1)](长度 2+2+1=52+2+1=5)以及 [(12,6),(6,3),(3,1)][(12, 6), (6, 3), (3, 1)](长度 2+2+1=52+2+1=5);
  • 第三个查询仅包含路径 [(3,1),(1,2),(2,4)][(3, 1), (1, 2), (2, 4)](长度 1+1+1=31+1+1=3)。

输入解题思路,AI测评打分。不知道怎么写?

首页