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⋅c=b.

For n≥2n≥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.

Input

The first line of the input is a single integer t (1≤t≤100)t (1≤t≤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≤n≤106,1≤k≤109), corresponding to a query by Orac.

It is guaranteed that the total sum of nn is at most 106106.

Output

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

Sample Input

3
5 1
8 2
3 4

Sample Output

10
12
12

Note

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)=5f(5)=5 to 5, and the result is 10.

In the second query, n=8and 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, nn is changed as follows: 3→6→8→10→123→6→8→10→12.

题目大意:

定义 f(n) 为 除了 1,n 之外的最小因子,需要进行 k次操作,每次将 n 加上 f(n)。

解题思路:

第一遍找约数,第二遍开始直接+2。从第二个开始,每个都和前面相差2,因此当k==1时,结果ans=n+f(n);当k>=2,ans=n+f(n)+(k-1)*2。

代码如下:

#include<iostream>
#include<algorithm>
#include<cstdio>using namespace std;int main()
{int t;scanf("%d",&t);while (t--) {int n,k;scanf("%d %d",&n,&k);if(n%2!=0){for(int i=2;i<=n;i++) {if(n%i==0) {n+=i;k--;break; }}}printf("%d\n",n+2*k);}return 0;
}

Orac and Factors相关推荐

  1. A.Orac and Factors

    先上题目链接:https://codeforces.com/contest/1350/problem/A 题目大意:给定一个数n,f(n)表示n的最小因子数(1除外),在给定次数k,每次计算f(n)+ ...

  2. 1096 Consecutive Factors

    1. 对于题目描述中 list the smallest sequence of the consecutive factors 正确理解是:如果有多组连续因子,输出开头因子最小的那个序列(一开始理解 ...

  3. Error in Math.factor() : ‘sqrt’ not meaningful for factors

    Error in Math.factor() : 'sqrt' not meaningful for factors 目录 Error in Math.factor() : 'sqrt' not me ...

  4. Error in contrasts can be applied only to factors with 2 or more levels

    Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only ...

  5. Error in Math.factor(x) : ‘abs’ not meaningful for factors

    Error in Math.factor(x) : 'abs' not meaningful for factors Error in Math.factor(x_fac): 'abs' not me ...

  6. R语言数据类型:Logical、Numeric、Integer、Complex、Character、Vectors、Lists、Matrices、Arrays、Factors、DataFrames

    R语言数据类型:Logical.Numeric.Integer.Complex.Character.Vectors.Lists.Matrices.Arrays.Factors.DataFrames 通 ...

  7. PAT甲级1096 Consecutive Factors :[C++题解]连续的因子、约数

    文章目录 题目分析 题目链接 题目分析 来源:acwing 题意重述:1个正整数N的因子中可能存在若干连续的数字.比如 N =630 ,N = 3 * 5 * 6 *7,这里连续的因子是5 *6 * ...

  8. PAT甲级1059 Prime Factors :[C++题解]分解质因子

    文章目录 题目分析 题目链接 题目分析 暴力求质因数 下面i就是质因子,s是质因子i的阶数. 暴力的时间复杂度O(n),会超时 void divide(int n){for(int i=2;i< ...

  9. 4kyu Sum by Factors

    4kyu Sum by Factors 题目背景: Given an array of positive or negative integers I= [i1,-,in] you have to p ...

最新文章

  1. 美式期权定价python_【优质好课】Python量化期权实战应用
  2. 吴世春:如何找到产品的引爆点
  3. Spring Cloud构建微服务架构:消息驱动的微服务(消费组)【Dalston版】
  4. 科大星云诗社动态20210830
  5. matlab if m不等于0,matlab问题clearfor a=0.1:0.1:50for b=0.1:0.1:20for m=0.1:0.1:5
  6. html表单实验总结,HTML表单总结
  7. 01屏幕增强 sap_SAP (MM01 MM02 MM03)屏幕增强
  8. cocos2d-x之猜数字游戏
  9. 问题:双击Excel文件提示文件找不到,只打开程序不同时打开文件,但通过打开对话框却能打开文件。
  10. java case 语句_Java switch case 语句
  11. 在IDEA中实现Python随机森林模型预测人口
  12. java简历中的项目经验怎么写_java软件工程师简历中项目经验怎么写?
  13. AutoCAD.net 自定义窗体及面板与CAD交互时的焦点切换问题(C#)
  14. Allpairs正交工具的安装、使用及错误提示解决办法
  15. element-ui ele-calendar 清除选中 事件
  16. jsp简介lamitry_[提拉米苏] 找人一起玩,今晚刚开的号
  17. 核磁共振设备工作过程人体温度监控中应用的光纤温度传感器
  18. 移动端touch拖动事件和click事件冲突问题解决
  19. 【云原生 | 12】Dockerfile语法详解及举例
  20. 今年最后一月数据库排名公布!前三难以撼动!

热门文章

  1. 工信部部长李毅中:警惕IBM智慧地球陷阱
  2. java bufferedimage 内存溢出_内存溢出使用ImageIO.write
  3. 矩阵 倒置 和 点积
  4. 【技术综述】最全人脸数据集收录
  5. 使用EasyRecovery来恢复误删的照片
  6. 移动mysql_MySQL移动数据库位置
  7. 本地安装易邮邮箱服务器并用foxmail 连接测试(内含邮箱网络传输的小知识.)
  8. Linux操作系统学习笔记(二十八)深入理解CPU
  9. windows系统下采用向日葵远程连接Ubuntu系统的服务器
  10. SongTaste闭站谢客 网络音乐731大限已至