CF2147G.Modular Tetration

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

For a positive integer aa, we define a recurrence bnn≥0{b_n}_{n\geq 0} as bn=abn−1b_n = a^{b_{n-1}}, with b0=1b_0 = 1.

We say that a positive integer aa is mm-tetrative if the sequence bb stabilizes to 11 modulo mm, that is, there exists N≥0N \ge 0 such that bn≡1(modm)b_n \equiv 1 \pmod m for all n≥Nn \geq N.

For a given mm, calculate the density of the mm-tetrative integers. Here, the density of a set SS is the limit $$\lim\limits_{n\rightarrow \infty}\frac{|S\cap [1,2,\ldots,n]|}{n}.$$ Informally, it is the "proportion" of positive integers that are mm-tetrative.

It can be proven (under the constraints of this problem) that the density is well-defined and is always a rational number, whose denominator is not divisible by 998 244 353998\,244\,353.

对于正整数 aa,我们定义一个递推序列 {bn}n≥0\{b_n\}_{n\geq 0}:bn=abn−1b_n = a^{b_{n-1}},其中 b0=1b_0 = 1。

若正整数 aa 满足:序列 bb 在模 mm 意义下稳定于 11,即存在 N≥0N \ge 0,使得对所有 n≥Nn \geq N 均有 bn≡1(modm)b_n \equiv 1 \pmod m,则称 aa 是 mm-四次幂型的(mm-tetrative)。

对给定的 mm,计算所有 mm-四次幂型正整数的密度。此处,集合 SS 的密度定义为极限

lim⁡n→∞∣S∩[1,2,…,n]∣n.\lim\limits_{n\rightarrow \infty}\frac{|S\cap [1,2,\ldots,n]|}{n}.

直观上,它表示正整数中 mm-四次幂型整数所占的“比例”。

可以证明(在本题约束条件下),该密度恒存在,且总是一个有理数,其分母不被 998 244 353998\,244\,353 整除。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The number mm will be given to you as a product of three integers xx, yy, and zz. The first and only line of each test case contains three integers xx, yy, zz (1≤x,y,z≤1061\leq x,y,z \leq 10^6, m=xyz≥2m = xyz \geq 2).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是测试用例的描述。

数字 mm 将以三个整数 xx、yy 和 zz 的乘积形式给出。每个测试用例的第一行且唯一一行包含三个整数 xx、yy、zz(1≤x,y,z≤1061\leq x,y,z \leq 10^6,且 m=xyz≥2m = xyz \geq 2)。

输出格式

For each test case, print the density of mm-tetrative integers (aa such that its corresponding sequence bnb_n converges to 11 modulo mm), modulo 998 244 353998\,244\,353.

Formally, let M=998 244 353M = 998\,244\,353. It can be shown that the exact answer can be expressed as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M}. Output the integer equal to p⋅q−1 mod Mp \cdot q^{-1} \bmod M. In other words, output such an integer xx that 0≤x<M0 \le x \lt M and x⋅q≡p(modM)x \cdot q \equiv p \pmod{M}.

对于每个测试用例,输出 mm-四重幂整数(即满足其对应序列 bnb_n 模 mm 收敛于 11 的整数 aa)的密度,对 998 244 353998\,244\,353 取模。

形式化地,令 M=998 244 353M = 998\,244\,353。可以证明,精确答案可表示为既约分数 pq\frac{p}{q},其中 pp 和 qq 为整数,且 q≢0(modM)q \not \equiv 0 \pmod{M}。请输出整数 p⋅q−1 mod Mp \cdot q^{-1} \bmod M。换言之,输出满足 0≤x<M0 \le x < M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M} 的整数 xx。

输入输出样例

  • 输入#1

    5
    5 1 1
    5 2 1
    23 1 1
    10 10 2
    9 3 37

    输出#1

    499122177
    299473306
    893685162
    913393583
    705965601

说明/提示

In the first test case, m=5m = 5. For example, a=1a=1 is 55-tetrative since bn=1b_n = 1 for all nn. For a=8a= 8, the sequence bb is [1,8,88,8(88),…][1, 8, 8^8, 8^{(8^8)}, \ldots], which is [1,3,1,1,…][1, 3, 1, 1, \ldots] if we look at it modulo 55. It can be proven that the sequence is always 1(mod5)1 \pmod 5 for big enough nn, so 88 is 55-tetrative. For a=10a=10, the sequence bb is [1,10,1010,10(1010),…][1, 10, 10^{10}, 10^{(10^{10})}, \ldots], which is [1,0,0,0,…][1, 0, 0, 0, \ldots] if we look at it modulo 55. It can be proven that the sequence is always 0(mod5)0 \pmod 5 for big enough nn, so 1010 is not 55-tetrative. The answer for the first test case is 12\frac{1}{2}.

In the second test case, m=10m= 10 and the answer is 110\frac{1}{10}.

In the third test case, m=23m= 23 and the answer is 63506\frac{63}{506}.

In the fourth test case, m=200m= 200 and the answer is 1200\frac{1}{200}.

In the fifth test case, m=999m= 999 and the answer is 1222\frac{1}{222}.

在第一个测试用例中,m=5m = 5。例如,a=1a=1 是 55-四叠数(55-tetrative),因为对所有 nn 均有 bn=1b_n = 1。对于 a=8a= 8,序列 bb 为 [1,8,88,8(88),…][1, 8, 8^8, 8^{(8^8)}, \ldots],若对其模 55 观察,则变为 [1,3,1,1,…][1, 3, 1, 1, \ldots]。可以证明:当 nn 足够大时,该序列恒满足 bn≡1(mod5)b_n \equiv 1 \pmod{5},因此 88 是 55-四叠数。对于 a=10a=10,序列 bb 为 [1,10,1010,10(1010),…][1, 10, 10^{10}, 10^{(10^{10})}, \ldots],若对其模 55 观察,则变为 [1,0,0,0,…][1, 0, 0, 0, \ldots]。可以证明:当 nn 足够大时,该序列恒满足 bn≡0(mod5)b_n \equiv 0 \pmod{5},因此 1010 不是 55-四叠数。第一个测试用例的答案为 12\frac{1}{2}。

在第二个测试用例中,m=10m= 10,答案为 110\frac{1}{10}。

在第三个测试用例中,m=23m= 23,答案为 63506\frac{63}{506}。

在第四个测试用例中,m=200m= 200,答案为 1200\frac{1}{200}。

在第五个测试用例中,m=999m= 999,答案为 1222\frac{1}{222}。

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

首页