CF2169D2.Removal of a Sequence (Hard Version)

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

This is the hard version of the problem. The difference between the versions is the constraint on xx; in this version, x≤1012x \le 10^{12}.

Polycarp has a sequence of all natural numbers from 11 to 101210^{12}. He decides to modify this sequence by performing the following action xx times:

  • Simultaneously remove all numbers at positions yy, 2⋅y2 \cdot y, 3⋅y3 \cdot y, ..., m⋅y≤nm \cdot y \le n, where nn is the length of the current sequence.

After that, Polycarp wants to find the kk-th number in the remaining sequence or determine that the length of the resulting sequence is less than kk.

Help Polycarp solve this problem!

Consider an example. Let x=2x = 2, y=3y = 3, k=5k = 5, then:

The numbers crossed out with a red line were removed after the first operation, and the numbers crossed out with a blue line were removed after the second operation. Thus, the number at position k=5k = 5 is the number 1010.

这是该问题的困难版本。两个版本的区别在于对 xx 的约束;在本版本中,x≤1012x \le 10^{12}。

Polycarp 拥有一个从 11 到 101210^{12} 的所有自然数构成的序列。他决定对该序列执行以下操作共 xx 次:

  • 同时删除当前序列中所有位于位置 yy、2⋅y2 \cdot y、3⋅y3 \cdot y、……、m⋅y≤nm \cdot y \le n 上的数,其中 nn 是当前序列的长度。

之后,Polycarp 希望找出剩余序列中第 kk 个数,或判断最终序列的长度是否小于 kk。

请帮助 Polycarp 解决这个问题!

考虑一个例子:设 x=2x = 2,y=3y = 3,k=5k = 5,则:

被红色线划掉的数字是在第一次操作后被删除的,被蓝色线划掉的数字是在第二次操作后被删除的。因此,位置 k=5k = 5 上的数是数字 1010。

输入格式

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

The only line of each test case contains three integers xx, yy, kk (1≤x,y,k≤10121 \le x, y, k \le 10^{12}).

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

每个测试用例仅有一行,包含三个整数 xx、yy、kk(1≤x,y,k≤10121 \le x, y, k \le 10^{12})。

输出格式

For each test case, output a positive integer that is at the kk-th position in the resulting sequence, or −1-1 if the length of the resulting sequence is less than kk.

对于每个测试用例,输出结果序列中第 kk 个位置上的正整数;若结果序列的长度小于 kk,则输出 −1-1。

输入输出样例

  • 输入#1

    6
    2 3 5
    2 5 1
    20 2 1000000000000
    175 10 28
    1000000000 998244353 1999999999
    1 1 1

    输出#1

    10
    1
    -1
    2339030304
    4672518823
    -1

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

首页