CF1350A.Orac and Factors

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Orac is studying number theory, and he is interested in the properties of divisors.

For two positive integers aa and bb, aa is a divisor of bb if and only if there exists an integer cc, such that a⋅c=ba\cdot c=b.

For n≥2n \ge 2, we will denote as f(n)f(n) the smallest positive divisor of nn, except 11.

For example, f(7)=7,f(10)=2,f(35)=5f(7)=7,f(10)=2,f(35)=5.

For the fixed integer nn, Orac decided to add f(n)f(n) to nn.

For example, if he had an integer n=5n=5, the new value of nn will be equal to 1010. And if he had an integer n=6n=6, nn will be changed to 88.

Orac loved it so much, so he decided to repeat this operation several times.

Now, for two positive integers nn and kk, Orac asked you to add f(n)f(n) to nn exactly kk times (note that nn will change after each operation, so f(n)f(n) may change too) and tell him the final value of nn.

For example, if Orac gives you n=5n=5 and k=2k=2, at first you should add f(5)=5f(5)=5 to n=5n=5, so your new value of nn will be equal to n=10n=10, after that, you should add f(10)=2f(10)=2 to 1010, so your new (and the final!) value of nn will be equal to 1212.

Orac may ask you these queries many times.

Orac 正在学习数论,他对约数的性质很感兴趣。

对于两个正整数 aa 和 bb,当且仅当存在某个整数 cc,使得 a⋅c=ba \cdot c = b 时,称 aa 是 bb 的一个约数。

对于 n≥2n \ge 2,我们记 f(n)f(n) 为 nn 的最小正约数(不包括 11)。

例如,f(7)=7f(7)=7,f(10)=2f(10)=2,f(35)=5f(35)=5。

对于给定的整数 nn,Orac 决定将 f(n)f(n) 加到 nn 上。

例如,若他初始有整数 n=5n=5,则 nn 的新值变为 1010;若初始有整数 n=6n=6,则 nn 将变为 88。

Orac 非常喜欢这个操作,因此决定重复执行该操作若干次。

现在,对于两个正整数 nn 和 kk,Orac 要求你对 nn 恰好执行 kk 次上述操作(注意:每次操作后 nn 的值都会改变,因此 f(n)f(n) 也可能随之改变),并告诉他最终的 nn 值。

例如,若 Orac 给出 n=5n=5 和 k=2k=2,首先你应将 f(5)=5f(5)=5 加到 n=5n=5 上,得到新的 n=10n=10;接着,你应将 f(10)=2f(10)=2 加到 1010 上,从而得到新的(也是最终的!)nn 值为 1212。

Orac 可能会多次向你提出此类查询。

输入格式

The first line of the input is a single integer t (1≤t≤100)t\ (1\le t\le 100): the number of times that Orac will ask you.

Each of the next tt lines contains two positive integers n,k (2≤n≤106,1≤k≤109)n,k\ (2\le n\le 10^6, 1\le k\le 10^9), corresponding to a query by Orac.

It is guaranteed that the total sum of nn is at most 10610^6.

输入的第一行是一个整数 t (1≤t≤100)t\ (1\le t\le 100):表示 Orac 向你提问的次数。

接下来的 tt 行,每行包含两个正整数 n,k (2≤n≤106,1≤k≤109)n,k\ (2\le n\le 10^6, 1\le k\le 10^9),对应一次 Orac 的查询。

保证所有查询中 nn 的总和不超过 10610^6。

输出格式

Print tt lines, the ii-th of them should contain the final value of nn in the ii-th query by Orac.

输出 tt 行,其中第 ii 行应包含 Orac 的第 ii 个查询中 nn 的最终值。

输入输出样例

  • 输入#1

    3
    5 1
    8 2
    3 4

    输出#1

    10
    12
    12

说明/提示

In the first query, n=5n=5 and k=1k=1. The divisors of 55 are 11 and 55, the smallest one except 11 is 55. Therefore, the only operation adds f(5)=5f(5)=5 to 55, and the result is 1010.

In the second query, n=8n=8 and k=2k=2. The divisors of 88 are 1,2,4,81,2,4,8, where the smallest one except 11 is 22, then after one operation 88 turns into 8+(f(8)=2)=108+(f(8)=2)=10. The divisors of 1010 are 1,2,5,101,2,5,10, where the smallest one except 11 is 22, therefore the answer is 10+(f(10)=2)=1210+(f(10)=2)=12.

In the third query, nn is changed as follows: 3→6→8→10→123 \to 6 \to 8 \to 10 \to 12.

在第一次查询中,n=5n=5 且 k=1k=1。55 的因数为 11 和 55,其中除 11 外最小的因数是 55。因此,唯一一次操作将 f(5)=5f(5)=5 加到 55 上,结果为 1010。

在第二次查询中,n=8n=8 且 k=2k=2。88 的因数为 1,2,4,81,2,4,8,其中除 11 外最小的因数是 22,因此经过一次操作后,88 变为 8+(f(8)=2)=108+(f(8)=2)=10。1010 的因数为 1,2,5,101,2,5,10,其中除 11 外最小的因数是 22,故答案为 10+(f(10)=2)=1210+(f(10)=2)=12。

在第三次查询中,nn 的变化过程如下:3→6→8→10→123 \to 6 \to 8 \to 10 \to 12。

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

首页