A13386 | Orac and Factors
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Orac is studying number theory, and he is interested in the properties of divisors.
For two positive integers $a$ and $b$ , $a$ is a divisor of $b$ if and only if there exists an integer $c$ , such that $a\cdot c=b$ .
For $n \ge 2$ , we will denote as $f(n)$ the smallest positive divisor of $n$ , except $1$ .
For example, $f(7)=7,f(10)=2,f(35)=5$ .
For the fixed integer $n$ , Orac decided to add $f(n)$ to $n$ .
For example, if he had an integer $n=5$ , the new value of $n$ will be equal to $10$ . And if he had an integer $n=6$ , $n$ will be changed to $8$ .
Orac loved it so much, so he decided to repeat this operation several times.
Now, for two positive integers $n$ and $k$ , Orac asked you to add $f(n)$ to $n$ exactly $k$ times (note that $n$ will change after each operation, so $f(n)$ may change too) and tell him the final value of $n$ .
For example, if Orac gives you $n=5$ and $k=2$ , at first you should add $f(5)=5$ to $n=5$ , so your new value of $n$ will be equal to $n=10$ , after that, you should add $f(10)=2$ to $10$ , so your new (and the final!) value of $n$ will be equal to $12$ .
Orac may ask you these queries many times.
For two positive integers $a$ and $b$ , $a$ is a divisor of $b$ if and only if there exists an integer $c$ , such that $a\cdot c=b$ .
For $n \ge 2$ , we will denote as $f(n)$ the smallest positive divisor of $n$ , except $1$ .
For example, $f(7)=7,f(10)=2,f(35)=5$ .
For the fixed integer $n$ , Orac decided to add $f(n)$ to $n$ .
For example, if he had an integer $n=5$ , the new value of $n$ will be equal to $10$ . And if he had an integer $n=6$ , $n$ will be changed to $8$ .
Orac loved it so much, so he decided to repeat this operation several times.
Now, for two positive integers $n$ and $k$ , Orac asked you to add $f(n)$ to $n$ exactly $k$ times (note that $n$ will change after each operation, so $f(n)$ may change too) and tell him the final value of $n$ .
For example, if Orac gives you $n=5$ and $k=2$ , at first you should add $f(5)=5$ to $n=5$ , so your new value of $n$ will be equal to $n=10$ , after that, you should add $f(10)=2$ to $10$ , so your new (and the final!) value of $n$ will be equal to $12$ .
Orac may ask you these queries many times.
输入格式
The first line of the input is a single integer $t\ (1\le t\le 100)$ : the number of times that Orac will ask you.
Each of the next $t$ lines contains two positive integers $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 $n$ is at most $10^6$ .
Each of the next $t$ lines contains two positive integers $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 $n$ is at most $10^6$ .
输出格式
Print $t$ lines, the $i$ -th of them should contain the final value of $n$ in the $i$ -th query by Orac.
输入输出样例
输入 #1
3 5 1 8 2 3 4
输出 #1
10 12 12
In the first query, $n=5$ and $k=1$ . The divisors of $5$ are $1$ and $5$ , the smallest one except $1$ is $5$ . Therefore, the only operation adds $f(5)=5$ to $5$ , and the result is $10$ .
In the second query, $n=8$ and $k=2$ . The divisors of $8$ are $1,2,4,8$ , where the smallest one except $1$ is $2$ , then after one operation $8$ turns into $8+(f(8)=2)=10$ . The divisors of $10$ are $1,2,5,10$ , where the smallest one except $1$ is $2$ , therefore the answer is $10+(f(10)=2)=12$ .
In the third query, $n$ is changed as follows: $3 \to 6 \to 8 \to 10 \to 12$ .
In the second query, $n=8$ and $k=2$ . The divisors of $8$ are $1,2,4,8$ , where the smallest one except $1$ is $2$ , then after one operation $8$ turns into $8+(f(8)=2)=10$ . The divisors of $10$ are $1,2,5,10$ , where the smallest one except $1$ is $2$ , therefore the answer is $10+(f(10)=2)=12$ .
In the third query, $n$ is changed as follows: $3 \to 6 \to 8 \to 10 \to 12$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted