CF920G.List Of Integers

提高+/省选-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's denote as L(x, p) an infinite sequence of integers y such that gcd(p, y) = 1 and y > x (where gcd is the greatest common divisor of two integer numbers), sorted in ascending order. The elements of L(x, p) are 1-indexed; for example, 9, 13 and 15 are the first, the second and the third elements of L(7, 22), respectively.

You have to process t queries. Each query is denoted by three integers x, p and k, and the answer to this query is k-th element of L(x, p).

我们用 L(x,p)L(x, p) 表示一个无限整数序列 yy,其中满足 gcd⁡(p,y)=1\gcd(p, y) = 1 且 y>xy > x(gcd⁡\gcd 表示两个整数的最大公约数),并按升序排列。L(x,p)L(x, p) 的元素采用 1-索引;例如,99、1313 和 1515 分别是 L(7,22)L(7, 22) 的第 11、第 22 和第 33 个元素。

你需要处理 tt 个查询。每个查询由三个整数 xx、pp 和 kk 给出,该查询的答案即为 L(x,p)L(x, p) 的第 kk 个元素。

输入格式

The first line contains one integer t (1 ≤ t ≤ 30000) — the number of queries to process.

Then t lines follow. i-th line contains three integers x, p and k for i-th query (1 ≤ x, p, k ≤ 106).

第一行包含一个整数 tt(1≤t≤300001 \leq t \leq 30000)—— 表示需要处理的查询数量。

接下来是 tt 行。第 ii 行包含三个整数 xx、pp 和 kk,对应第 ii 个查询(1≤x,p,k≤1061 \leq x, p, k \leq 10^6)。

输出格式

Print t integers, where i-th integer is the answer to i-th query.

输出 t 个整数,其中第 i 个整数是第 i 个查询的答案。

输入输出样例

  • 输入#1

    3
    7 22 1
    7 22 2
    7 22 3

    输出#1

    9
    13
    15
  • 输入#2

    5
    42 42 42
    43 43 43
    44 44 44
    45 45 45
    46 46 46

    输出#2

    187
    87
    139
    128
    141

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

首页