import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Cf131 implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt()
        {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do
            {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception
    {
        new Thread(null, new Cf131(),"Main",1<<27).start();
    }

    static class Pair{
        int nod;
        int ucn;

        Pair(int nod,int ucn){
            this.nod=nod;
            this.ucn=ucn;

        }

    public static Comparator<Pair> wc = new Comparator<Pair>(){
        public int compare(Pair e1,Pair e2){

            //reverse order
            if (e1.ucn < e2.ucn)
                return 1;  // 1 for swaping.
            else if (e1.ucn > e2.ucn)
                return -1;
            else{
                // if(e1.siz>e2.siz)
                //     return 1;
                // else
                //     return -1;
                return 0;
            }
        }
    };
    }

    public static long gcd(long a,long b){
        if(b==0)return a;
        else return gcd(b,a%b);
    }

    ////recursive BFS
    public static int bfsr(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,int[] pre){
        b[s]=true;
        int p = 0;
        int t = a[s].size();
        for(int i=0;i<t;i++){
            int x = a[s].get(i);
            if(!b[x]){
                dist[x] = dist[s] + 1;
                p+= (bfsr(x,a,dist,b,pre)+1);
            }
        }
        pre[s] = p;
        return p;
    }

//// iterative BFS
    public static int bfs(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,PrintWriter w){
        b[s]=true;
        int siz = 0;

        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        while(q.size()!=0){
            int i=q.poll();
        //    w.println(" #"+i+"# ");
            Iterator<Integer> it =a[i].listIterator();
            int z=0;
            while(it.hasNext()){
                z=it.next();
               // w.println("#"+i+" "+z);
                if(!b[z]){
                //    w.println("* "+z+" *");
                    b[z]=true;
                    dist[z] = dist[i] + 1;
                 //   w.print("*");
                   // w.println(i+" "+z);
                    siz++;
                //    x.add(z);
                //    w.println("@ "+x.get(x.size()-1)+" @");
                    q.add(z);
                }
            }

        }
        return siz;
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        // int defaultValue=0;
        // int[] a = new int[15000003];
        // for(int i=2;i<a.length;i++){
        //     boolean f = true;
        //     for(int j=2;j<=(int)(double)Math.sqrt(i);j++){
        //         if(i%j==0){a[i]=j;f = false;break;}

        //     }
        //     if(f)a[i] = i;
        // }

        int t = sc.nextInt();
        while(t-->0){

            int n = sc.nextInt();
            int k = sc.nextInt();
            int ans = n;
            while(k-->0){
               if(ans%2==0)ans+=2;
               else{
                boolean f = true;
                    for(int j=2;j<=(int)(double)Math.sqrt(ans);j++){
                        if(ans%j==0){ans+=j;f = false;break;}

                    }
                    if(f)ans+=ans;
               }
            }
            w.println(ans);

        }
        w.flush();
        w.close();

    }

}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Cf131 implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt()
        {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do
            {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception
    {
        new Thread(null, new Cf131(),"Main",1<<27).start();
    }

    static class Pair{
        int nod;
        int ucn;

        Pair(int nod,int ucn){
            this.nod=nod;
            this.ucn=ucn;

        }

    public static Comparator<Pair> wc = new Comparator<Pair>(){
        public int compare(Pair e1,Pair e2){

            //reverse order
            if (e1.ucn < e2.ucn)
                return 1;  // 1 for swaping.
            else if (e1.ucn > e2.ucn)
                return -1;
            else{
                // if(e1.siz>e2.siz)
                //     return 1;
                // else
                //     return -1;
                return 0;
            }
        }
    };
    }

    public static long gcd(long a,long b){
        if(b==0)return a;
        else return gcd(b,a%b);
    }

    ////recursive BFS
    public static int bfsr(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,int[] pre){
        b[s]=true;
        int p = 0;
        int t = a[s].size();
        for(int i=0;i<t;i++){
            int x = a[s].get(i);
            if(!b[x]){
                dist[x] = dist[s] + 1;
                p+= (bfsr(x,a,dist,b,pre)+1);
            }
        }
        pre[s] = p;
        return p;
    }

//// iterative BFS
    public static int bfs(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,PrintWriter w){
        b[s]=true;
        int siz = 0;

        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        while(q.size()!=0){
            int i=q.poll();
        //    w.println(" #"+i+"# ");
            Iterator<Integer> it =a[i].listIterator();
            int z=0;
            while(it.hasNext()){
                z=it.next();
               // w.println("#"+i+" "+z);
                if(!b[z]){
                //    w.println("* "+z+" *");
                    b[z]=true;
                    dist[z] = dist[i] + 1;
                 //   w.print("*");
                   // w.println(i+" "+z);
                    siz++;
                //    x.add(z);
                //    w.println("@ "+x.get(x.size()-1)+" @");
                    q.add(z);
                }
            }

        }
        return siz;
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        int defaultValue=0;
        int[] a = new int[1000001];
        for(int i=2;i<a.length;i++){
            boolean f = true;
            for(int j=2;j<=(int)(double)Math.sqrt(i);j++){
                if(i%j==0){a[i]=j;f = false;break;}

            }
            if(f)a[i] = i;
        }

        int t = sc.nextInt();
        while(t-->0){

            int n = sc.nextInt();
            int k = sc.nextInt();
            int ans = n;
            while(k-->0){
                ans += a[ans];
            }
            w.println(ans);

        }
        w.flush();
        w.close();

    }

}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Cf131 implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt()
        {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do
            {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception
    {
        new Thread(null, new Cf131(),"Main",1<<27).start();
    }

    static class Pair{
        int nod;
        int ucn;

        Pair(int nod,int ucn){
            this.nod=nod;
            this.ucn=ucn;

        }

    public static Comparator<Pair> wc = new Comparator<Pair>(){
        public int compare(Pair e1,Pair e2){

            //reverse order
            if (e1.ucn < e2.ucn)
                return 1;  // 1 for swaping.
            else if (e1.ucn > e2.ucn)
                return -1;
            else{
                // if(e1.siz>e2.siz)
                //     return 1;
                // else
                //     return -1;
                return 0;
            }
        }
    };
    }

    public static long gcd(long a,long b){
        if(b==0)return a;
        else return gcd(b,a%b);
    }

    ////recursive BFS
    public static int bfsr(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,int[] pre){
        b[s]=true;
        int p = 0;
        int t = a[s].size();
        for(int i=0;i<t;i++){
            int x = a[s].get(i);
            if(!b[x]){
                dist[x] = dist[s] + 1;
                p+= (bfsr(x,a,dist,b,pre)+1);
            }
        }
        pre[s] = p;
        return p;
    }

//// iterative BFS
    public static int bfs(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,PrintWriter w){
        b[s]=true;
        int siz = 0;

        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        while(q.size()!=0){
            int i=q.poll();
        //    w.println(" #"+i+"# ");
            Iterator<Integer> it =a[i].listIterator();
            int z=0;
            while(it.hasNext()){
                z=it.next();
               // w.println("#"+i+" "+z);
                if(!b[z]){
                //    w.println("* "+z+" *");
                    b[z]=true;
                    dist[z] = dist[i] + 1;
                 //   w.print("*");
                   // w.println(i+" "+z);
                    siz++;
                //    x.add(z);
                //    w.println("@ "+x.get(x.size()-1)+" @");
                    q.add(z);
                }
            }

        }
        return siz;
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        int defaultValue=0;
        int[] a = new int[200000003];
        for(int i=2;i<a.length;i++){
            boolean f = true;
            for(int j=2;j<=(int)(double)Math.sqrt(i);j++){
                if(i%j==0){a[i]=j;f = false;break;}

            }
            if(f)a[i] = i;
        }

        int t = sc.nextInt();
        while(t-->0){

            int n = sc.nextInt();
            int k = sc.nextInt();
            int ans = n;
            while(k-->0){
                ans += a[ans];
            }
            w.println(ans);

        }
        w.flush();
        w.close();

    }

}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Cf131 implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt()
        {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do
            {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception
    {
        new Thread(null, new Cf131(),"Main",1<<27).start();
    }

    static class Pair{
        int nod;
        int ucn;

        Pair(int nod,int ucn){
            this.nod=nod;
            this.ucn=ucn;

        }

    public static Comparator<Pair> wc = new Comparator<Pair>(){
        public int compare(Pair e1,Pair e2){

            //reverse order
            if (e1.ucn < e2.ucn)
                return 1;  // 1 for swaping.
            else if (e1.ucn > e2.ucn)
                return -1;
            else{
                // if(e1.siz>e2.siz)
                //     return 1;
                // else
                //     return -1;
                return 0;
            }
        }
    };
    }

    public static long gcd(long a,long b){
        if(b==0)return a;
        else return gcd(b,a%b);
    }

    ////recursive BFS
    public static int bfsr(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,int[] pre){
        b[s]=true;
        int p = 0;
        int t = a[s].size();
        for(int i=0;i<t;i++){
            int x = a[s].get(i);
            if(!b[x]){
                dist[x] = dist[s] + 1;
                p+= (bfsr(x,a,dist,b,pre)+1);
            }
        }
        pre[s] = p;
        return p;
    }

//// iterative BFS
    public static int bfs(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,PrintWriter w){
        b[s]=true;
        int siz = 0;

        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        while(q.size()!=0){
            int i=q.poll();
        //    w.println(" #"+i+"# ");
            Iterator<Integer> it =a[i].listIterator();
            int z=0;
            while(it.hasNext()){
                z=it.next();
               // w.println("#"+i+" "+z);
                if(!b[z]){
                //    w.println("* "+z+" *");
                    b[z]=true;
                    dist[z] = dist[i] + 1;
                 //   w.print("*");
                   // w.println(i+" "+z);
                    siz++;
                //    x.add(z);
                //    w.println("@ "+x.get(x.size()-1)+" @");
                    q.add(z);
                }
            }

        }
        return siz;
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        int defaultValue=0;
        int[] a = new int[150000003];
        for(int i=2;i<a.length;i++){
            boolean f = true;
            for(int j=2;j<=(int)(double)Math.sqrt(i);j++){
                if(i%j==0){a[i]=j;f = false;break;}

            }
            if(f)a[i] = i;
        }

        int t = sc.nextInt();
        while(t-->0){

            int n = sc.nextInt();
            int k = sc.nextInt();
            int ans = n;
            while(k-->0){
                ans += a[ans];
            }
            w.println(ans);

        }
        w.flush();
        w.close();

    }

}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Cf131 implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt()
        {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do
            {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception
    {
        new Thread(null, new Cf131(),"Main",1<<27).start();
    }

    static class Pair{
        int nod;
        int ucn;

        Pair(int nod,int ucn){
            this.nod=nod;
            this.ucn=ucn;

        }

    public static Comparator<Pair> wc = new Comparator<Pair>(){
        public int compare(Pair e1,Pair e2){

            //reverse order
            if (e1.ucn < e2.ucn)
                return 1;  // 1 for swaping.
            else if (e1.ucn > e2.ucn)
                return -1;
            else{
                // if(e1.siz>e2.siz)
                //     return 1;
                // else
                //     return -1;
                return 0;
            }
        }
    };
    }

    public static long gcd(long a,long b){
        if(b==0)return a;
        else return gcd(b,a%b);
    }

    ////recursive BFS
    public static int bfsr(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,int[] pre){
        b[s]=true;
        int p = 0;
        int t = a[s].size();
        for(int i=0;i<t;i++){
            int x = a[s].get(i);
            if(!b[x]){
                dist[x] = dist[s] + 1;
                p+= (bfsr(x,a,dist,b,pre)+1);
            }
        }
        pre[s] = p;
        return p;
    }

//// iterative BFS
    public static int bfs(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,PrintWriter w){
        b[s]=true;
        int siz = 0;

        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        while(q.size()!=0){
            int i=q.poll();
        //    w.println(" #"+i+"# ");
            Iterator<Integer> it =a[i].listIterator();
            int z=0;
            while(it.hasNext()){
                z=it.next();
               // w.println("#"+i+" "+z);
                if(!b[z]){
                //    w.println("* "+z+" *");
                    b[z]=true;
                    dist[z] = dist[i] + 1;
                 //   w.print("*");
                   // w.println(i+" "+z);
                    siz++;
                //    x.add(z);
                //    w.println("@ "+x.get(x.size()-1)+" @");
                    q.add(z);
                }
            }

        }
        return siz;
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        // int defaultValue=0;
        // int[] a = new int[15000003];
        // for(int i=2;i<a.length;i++){
        //     boolean f = true;
        //     for(int j=2;j<=(int)(double)Math.sqrt(i);j++){
        //         if(i%j==0){a[i]=j;f = false;break;}

        //     }
        //     if(f)a[i] = i;
        // }

        int t = sc.nextInt();
        while(t-->0){

            int n = sc.nextInt();
            int k = sc.nextInt();
            int ans = n;
            while(k>0){
               if(ans%2==0){ans+=(2*k);k=0;break;}
               else{
                boolean f = true;
                    for(int j=2;j<=(int)(double)Math.sqrt(ans);j++){
                        if(ans%j==0){ans+=j;f = false;break;}

                    }
                    if(f)ans+=ans;
               }
               k--;
            }
            w.println(ans);

        }
        w.flush();
        w.close();

    }

}


import java.util.*;
import java.io.*;

public class Main {

    static PrintWriter out;
    static FastReader fr;
    // make it false if Multiple test case is not in the question
    final static boolean multipleTC = true;
    // Global Variables
    final static int MOD = (int) 1e9 + 7;
    final static double INF = Double.POSITIVE_INFINITY;
    final static int MAX = (int) 1e4;
    static int TestCase = 1;
    final ArrayList<Integer> primes = new ArrayList<>();

    // for pre processing if needed
    void pre() throws Exception {
        boolean[] prime = new boolean[MAX];
        primes.add(2);
        Arrays.fill(prime, true);

        prime[2] = true;
        for (int i = 2; i < MAX; i += 2) {
            prime[i] = false;
        }
        for (int i = 3; i < MAX; i += 2) {
            if (prime[i]) {
                for (int j = i * i; j < MAX; j += i) {
                    prime[j] = false;
                }
            }
        }
        for (int i = 3; i < MAX; i++) {
            if (prime[i]) {
                primes.add(i);
            }
        }

    }

    public static void main(String[] args) throws Exception {

        new Main().run();
    }

    // input output handled here
    private Object solve() throws Exception {
        // code
        long n = fr.nl(), k = fr.nl();

        long ans = n;

        if ((n & 1) == 1) {
            long fn = f(n);
            ans += fn + (k - 1) * 2;
        } else {
            ans += (k) * 2;
        }
        // for (int i = 1; i <= k; i++) {
        // long fn = f(n);
        // // deb(fn);
        // ans = fn + n;
        // n = ans;
        // }
        // deb(primes);
        return ans;
    }

    private long f(long n) {
        for (int p : primes) {
            if (p >= n)
                return n;
            if (n % p == 0)
                return p;
        }
        return 0;
    }

    void run() throws Exception {
        // long start_time = System.nanoTime();

        try {
            fr = new FastReader("in0.txt");
            out = new PrintWriter("out0.txt");
        } catch (Exception e) {
            fr = new FastReader();
            out = new PrintWriter(System.out);
        }
        pre();
        StringBuilder print = new StringBuilder("");

        int T = (multipleTC) ? fr.ni() : 1;
        for (TestCase = 1; TestCase <= T - 1; TestCase++) {
            print.append(solve()).append("\n");
        }
        print.append(solve());
        p(print);
        // long end_time = System.nanoTime();
        // System.out.printf("Running Time in sec : %2.10f", (double) (end_time -
        // start_time) * (double) 1e-9);

        out.flush();
        out.close();
    }

    static void p(Object o) {
        out.print(o);
    }

    static void pln(Object o) {
        out.println(o);
    }

    static void psp(Object o) {
        out.print(o + " ");
    }

    static void pnf(Object o) {
        out.println(o);
        out.flush();
    }

    static void deb(Object... x) {
        System.out.print("#" + TestCase + " = ");
        for (int i = 0; i < x.length - 1; i++)
            System.out.print(x[i] + " , ");
        System.out.println(x[x.length - 1]);

    }

    public <Type> Type also(Type a, Type b) throws Exception {
        return a;
    }

    class FastReader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public FastReader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public FastReader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String next() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == ' ')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }

        String n() throws Exception {
            return fr.next();
        }

        String nln() throws Exception {
            return fr.readLine().trim();
        }

        int ni() throws Exception {
            return fr.nextInt();
        }

        long nl() throws Exception {
            return fr.nextLong();
        }

        double nd() throws Exception {
            return fr.nextDouble();
        }

        int[] nextIntArray(int n) throws Exception {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = fr.nextInt();
            }
            return a;
        }

        long[] nextLongArray(int n) throws Exception {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = fr.nextLong();
            }
            return a;
        }
    }

}


import java.util.*;
import java.io.*;

public class Main {

    static PrintWriter out;
    static FastReader fr;
    // make it false if Multiple test case is not in the question
    final static boolean multipleTC = true;
    // Global Variables
    final static int MOD = (int) 1e9 + 7;
    final static double INF = Double.POSITIVE_INFINITY;
    final static int MAX = (int) 1e4;
    static int TestCase = 1;
    final ArrayList<Integer> primes = new ArrayList<>();

    // for pre processing if needed
    void pre() throws Exception {
        boolean[] prime = new boolean[MAX];
        primes.add(2);
        Arrays.fill(prime, true);

        prime[2] = true;
        for (int i = 2; i < MAX; i += 2) {
            prime[i] = false;
        }
        for (int i = 3; i < MAX; i += 2) {
            if (prime[i]) {
                for (int j = i * i; j < MAX; j += i) {
                    prime[j] = false;
                }
            }
        }
        for (int i = 3; i < MAX; i++) {
            if (prime[i]) {
                primes.add(i);
            }
        }

    }

    public static void main(String[] args) throws Exception {

        new Main().run();
    }

    // input output handled here
    private Object solve() throws Exception {
        // code
        long n = fr.nl(), k = fr.nl();
        long ans = 0;
        for (int i = 1; i <= k; i++) {
            long fn = f(n);
            // deb(fn);
            ans = fn + n;
            n = ans;
        }
        // deb(primes);
        return ans;
    }

    private long f(long n) {
        for (int p : primes) {
            if (p >= n)
                return n;
            if (n % p == 0)
                return p;
        }
        return 0;
    }

    void run() throws Exception {
        // long start_time = System.nanoTime();

        try {
            fr = new FastReader("in0.txt");
            out = new PrintWriter("out0.txt");
        } catch (Exception e) {
            fr = new FastReader();
            out = new PrintWriter(System.out);
        }
        pre();
        StringBuilder print = new StringBuilder("");

        int T = (multipleTC) ? fr.ni() : 1;
        for (TestCase = 1; TestCase <= T - 1; TestCase++) {
            print.append(solve()).append("\n");
        }
        print.append(solve());
        p(print);
        // long end_time = System.nanoTime();
        // System.out.printf("Running Time in sec : %2.10f", (double) (end_time -
        // start_time) * (double) 1e-9);

        out.flush();
        out.close();
    }

    static void p(Object o) {
        out.print(o);
    }

    static void pln(Object o) {
        out.println(o);
    }

    static void psp(Object o) {
        out.print(o + " ");
    }

    static void pnf(Object o) {
        out.println(o);
        out.flush();
    }

    static void deb(Object... x) {
        System.out.print("#" + TestCase + " = ");
        for (int i = 0; i < x.length - 1; i++)
            System.out.print(x[i] + " , ");
        System.out.println(x[x.length - 1]);

    }

    public <Type> Type also(Type a, Type b) throws Exception {
        return a;
    }

    class FastReader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public FastReader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public FastReader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String next() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == ' ')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }

        String n() throws Exception {
            return fr.next();
        }

        String nln() throws Exception {
            return fr.readLine().trim();
        }

        int ni() throws Exception {
            return fr.nextInt();
        }

        long nl() throws Exception {
            return fr.nextLong();
        }

        double nd() throws Exception {
            return fr.nextDouble();
        }

        int[] nextIntArray(int n) throws Exception {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = fr.nextInt();
            }
            return a;
        }

        long[] nextLongArray(int n) throws Exception {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = fr.nextLong();
            }
            return a;
        }
    }

}


import java.util.*;
import java.io.*;

public class Main {

    static PrintWriter out;
    static FastReader fr;
    // make it false if Multiple test case is not in the question
    final static boolean multipleTC = true;
    // Global Variables
    final static int MOD = (int) 1e9 + 7;
    final static double INF = Double.POSITIVE_INFINITY;
    final static int MAX = (int) 1e4;
    static int TestCase = 1;
    final ArrayList<Integer> primes = new ArrayList<>();

    // for pre processing if needed
    void pre() throws Exception {
        boolean[] prime = new boolean[MAX];
        primes.add(2);
        Arrays.fill(prime, true);

        prime[2] = true;
        for (int i = 2; i < MAX; i += 2) {
            prime[i] = false;
        }
        for (int i = 3; i < MAX; i += 2) {
            if (prime[i]) {
                for (int j = i * i; j < MAX; j += i) {
                    prime[j] = false;
                }
            }
        }
        for (int i = 3; i < MAX; i++) {
            if (prime[i]) {
                primes.add(i);
            }
        }

    }

    public static void main(String[] args) throws Exception {

        new Main().run();
    }

    // input output handled here
    private Object solve() throws Exception {
        // code
        long n = fr.nl(), k = fr.nl();

        long ans = 0;

        if ((n & 1) == 1) {
            long fn = f(n);
            ans = (n + fn) + ((k - 1) * 2);
        } else {
            ans = n + (k * 2);
        }

        return ans;
    }

    private long f(long n) {
        long res = n;
        for (long i = n; i >= 2; i--) {
            if (n % i == 0)
                res = i;
        }
        return res;
    }

    void run() throws Exception {
        // long start_time = System.nanoTime();

        try {
            fr = new FastReader("in0.txt");
            out = new PrintWriter("out0.txt");
        } catch (Exception e) {
            fr = new FastReader();
            out = new PrintWriter(System.out);
        }
        // pre();
        StringBuilder print = new StringBuilder("");

        int T = (multipleTC) ? fr.ni() : 1;
        for (TestCase = 1; TestCase <= T - 1; TestCase++) {
            print.append(solve()).append("\n");
        }
        print.append(solve());
        p(print);
        // long end_time = System.nanoTime();
        // System.out.printf("Running Time in sec : %2.10f", (double) (end_time -
        // start_time) * (double) 1e-9);

        out.flush();
        out.close();
    }

    static void p(Object o) {
        out.print(o);
    }

    static void pln(Object o) {
        out.println(o);
    }

    static void psp(Object o) {
        out.print(o + " ");
    }

    static void pnf(Object o) {
        out.println(o);
        out.flush();
    }

    static void deb(Object... x) {
        System.out.print("#" + TestCase + " = ");
        for (int i = 0; i < x.length - 1; i++)
            System.out.print(x[i] + " , ");
        System.out.println(x[x.length - 1]);

    }

    public <Type> Type also(Type a, Type b) throws Exception {
        return a;
    }

    class FastReader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public FastReader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public FastReader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String next() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == ' ')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }

        String n() throws Exception {
            return fr.next();
        }

        String nln() throws Exception {
            return fr.readLine().trim();
        }

        int ni() throws Exception {
            return fr.nextInt();
        }

        long nl() throws Exception {
            return fr.nextLong();
        }

        double nd() throws Exception {
            return fr.nextDouble();
        }

        int[] nextIntArray(int n) throws Exception {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = fr.nextInt();
            }
            return a;
        }

        long[] nextLongArray(int n) throws Exception {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = fr.nextLong();
            }
            return a;
        }
    }

}


// Working program with FastReader
import java.io.*;
import java.util.*;

public class codeforces_1350A
{
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args)
	{
		FastReader ob=new FastReader();
		int t=ob.nextInt();
        for (int i = 0; i <t ; i++) {
            long n=ob.nextLong(),k=ob.nextLong();
            while(k>0){
                for (int j = 2; j <=n ; j++) {
                    if(n%j==0){
                        n+=(long)j;
                        break;
                    }
                }
                k--;
            }
            System.out.println(n);
        }

	}
}


// Working program with FastReader
import java.io.*;
import java.util.*;

public class codeforces_1350A
{
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

	static void solve(FastReader ob){
	    long n=ob.nextLong(),k=ob.nextLong();
	    long ans=0;
	    if(n%2==0){
	        ans+=n+(k*2);
        }
	    else{
            for (int i = 3; i<=n ; i++) {
                if(n%i==0){
                    ans+=(n+i);
                }
            }

            ans+=((k-1)*2);
        }
        System.out.println(ans);
    }
	public static void main(String[] args)
	{
		FastReader ob=new FastReader();
		int t=ob.nextInt();
        for (int i = 0; i <t ; i++) {
            solve(ob);
        }

	}
}


// Working program with FastReader
import java.io.*;
import java.util.*;

public class codeforces_1350A
{
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args)
	{
		FastReader ob=new FastReader();
		int t=ob.nextInt();
        for (int i = 0; i <t ; i++) {
            long n=ob.nextLong(),k=ob.nextLong();
            boolean flag=true;
            while(k>0){
                for (int j = 2; j*j <=n ; j++) {
                    if(n%j==0){
                        n+=(long)j;
                        flag=false;
                        break;
                    }
                }
                if(flag){
                    n+=n;
                }
                k--;
            }
            System.out.println(n);
        }

	}
}


// Working program with FastReader
import java.io.*;
import java.util.*;

public class codeforces_1350A
{
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

	static void solve(FastReader ob){
	    long n=ob.nextLong(),k=ob.nextLong();
	    long ans=0;
	    if(n%2==0){
	        ans+=n+(k*2);
        }
	    else{
            for (int i = 3; i*i <=n ; i++) {
                if(n%i==0){
                    ans+=(n+i);
                }
            }
            if(ans==0){
                ans+=2*n;
            }
            ans+=((k-1)*2);
        }
        System.out.println(ans);
    }
	public static void main(String[] args)
	{
		FastReader ob=new FastReader();
		int t=ob.nextInt();
        for (int i = 0; i <t ; i++) {
            solve(ob);
        }

	}
}


// Working program with FastReader
import java.io.*;
import java.util.*;

public class codeforces_1350A
{
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

	static void solve(FastReader ob){
	    long n=ob.nextLong(),k=ob.nextLong();
	    long ans=0;
	    if(n%2==0){
	        ans+=n+(k*2);
        }
	    else{
            for (int i = 3; i<=n ; i++) {
                if(n%i==0){
                    ans+=(n+i);
                    break;
                }
            }

            ans+=((k-1)*2);
        }
        System.out.println(ans);
    }
	public static void main(String[] args)
	{
		FastReader ob=new FastReader();
		int t=ob.nextInt();
        for (int i = 0; i <t ; i++) {
            solve(ob);
        }

	}
}


import java.util.*;
import java.io.*;
public class Main {
        static public class InputIterator{
          ArrayList<String> inputLine = new ArrayList<String>(1024);
          int index = 0;
          int max;
          InputIterator(){
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while(true){
              String read;
              try{
                read = br.readLine();
              }catch(IOException e){
                read = null;
              }
              if(read != null){
                inputLine.add(read);
              }else{
                break;
              }
            }
            max = inputLine.size();
          }
          public boolean hasNext(){return (index < max);}
          public String next(){
            if(hasNext()){
              String returnStr = inputLine.get(index);
              index++;
              return returnStr;
            }else{
              throw new IndexOutOfBoundsException("これ以上入力はないよ。");
            }
          }
        }

        static InputIterator ii = new InputIterator();
        static void myout(Object t){System.out.println(t);}
        static void myerr(Object t){System.err.println(t);}
        static String next(){return ii.next();}
        static int nextInt(){return Integer.parseInt(next());}
        static long nextLong(){return Long.parseLong(next());}
        static String[] nextStrArray(){return next().split(" ");}
        static ArrayList<Integer> nextIntArray(){
          ArrayList<Integer> ret = new ArrayList<Integer>();
          String[] input = nextStrArray();
          for(int i = 0; i < input.length; i++){
            ret.add(Integer.parseInt(input[i]));
          }
          return ret;
        }
        static ArrayList<Long> nextLongArray(){
          ArrayList<Long> ret = new ArrayList<Long>();
          String[] input = nextStrArray();
          for(int i = 0; i < input.length; i++){
            ret.add(Long.parseLong(input[i]));
          }
          return ret;
        }
        static char[] nextCharArray(){return mySplit(next());}
        static char[] mySplit(String str){return str.toCharArray();}
        static String kaigyoToStr(String[] list){return String.join("\n",list);}
        static String kaigyoToStr(ArrayList<String> list){return String.join("\n",list);}
        static String hanSpToStr(String[] list){return String.join(" ",list);}
        static String hanSpToStr(ArrayList<String> list){return String.join(" ",list);}
        public static void main(String[] args){
          int t = nextInt();
	for(int i = 0; i < t; i++){
		ArrayList<Long> tmp = nextLongArray();
		long N = tmp.get(0);
		long K = tmp.get(1);
		LinkedList<Long> list = getDivisorList(N);
		long last = list.get(1);
		while(isPrime(N) && K > 0){
			N += N;
			K--;
			list = getDivisorList(N);
			last = list.get(1);
          	myerr(last);
		}
		N += (last * K);
		myout(N);
	}
        }
        //Method addition frame start
public static LinkedList<Long> getDivisorList(long val){
        LinkedList<Long> list = new LinkedList<Long>();
        for(long i = 1; i * i <= val; i++){
                if(val % i == 0){
                        list.add(i);
                        if(i * i != val){
                                list.add(val / i);
                        }
                }
        }
        Collections.sort(list, Comparator.naturalOrder());
        return list;
}
  static boolean isPrime(long val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        double root = Math.floor(Math.sqrt(val));
        for(long i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
        //Method addition frame end
}


import java.util.*;
import java.io.*;
public class Main {
        static public class InputIterator{
          ArrayList<String> inputLine = new ArrayList<String>(1024);
          int index = 0;
          int max;
          InputIterator(){
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while(true){
              String read;
              try{
                read = br.readLine();
              }catch(IOException e){
                read = null;
              }
              if(read != null){
                inputLine.add(read);
              }else{
                break;
              }
            }
            max = inputLine.size();
          }
          public boolean hasNext(){return (index < max);}
          public String next(){
            if(hasNext()){
              String returnStr = inputLine.get(index);
              index++;
              return returnStr;
            }else{
              throw new IndexOutOfBoundsException("これ以上入力はないよ。");
            }
          }
        }

        static InputIterator ii = new InputIterator();
        static void myout(Object t){System.out.println(t);}
        static void myerr(Object t){System.err.println(t);}
        static String next(){return ii.next();}
        static int nextInt(){return Integer.parseInt(next());}
        static long nextLong(){return Long.parseLong(next());}
        static String[] nextStrArray(){return next().split(" ");}
        static ArrayList<Integer> nextIntArray(){
          ArrayList<Integer> ret = new ArrayList<Integer>();
          String[] input = nextStrArray();
          for(int i = 0; i < input.length; i++){
            ret.add(Integer.parseInt(input[i]));
          }
          return ret;
        }
        static ArrayList<Long> nextLongArray(){
          ArrayList<Long> ret = new ArrayList<Long>();
          String[] input = nextStrArray();
          for(int i = 0; i < input.length; i++){
            ret.add(Long.parseLong(input[i]));
          }
          return ret;
        }
        static char[] nextCharArray(){return mySplit(next());}
        static char[] mySplit(String str){return str.toCharArray();}
        static String kaigyoToStr(String[] list){return String.join("\n",list);}
        static String kaigyoToStr(ArrayList<String> list){return String.join("\n",list);}
        static String hanSpToStr(String[] list){return String.join(" ",list);}
        static String hanSpToStr(ArrayList<String> list){return String.join(" ",list);}
        public static void main(String[] args){
          int t = nextInt();
	for(int i = 0; i < t; i++){
		ArrayList<Long> tmp = nextLongArray();
		long N = tmp.get(0);
		long K = tmp.get(1);
		LinkedList<Long> list = getDivisorList(N);
		long last = list.get(1);
      N += last;
      K--;
      list = getDivisorList(N);
      N += list.get(1) * K;

		myout(N);
	}
        }
        //Method addition frame start
public static LinkedList<Long> getDivisorList(long val){
        LinkedList<Long> list = new LinkedList<Long>();
        for(long i = 1; i * i <= val; i++){
                if(val % i == 0){
                        list.add(i);
                        if(i * i != val){
                                list.add(val / i);
                        }
                }
        }
        Collections.sort(list, Comparator.naturalOrder());
        return list;
}
  static boolean isPrime(long val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        double root = Math.floor(Math.sqrt(val));
        for(long i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
        //Method addition frame end
}


import java.util.*;
import java.io.*;
public class Main {
        static public class InputIterator{
          ArrayList<String> inputLine = new ArrayList<String>(1024);
          int index = 0;
          int max;
          InputIterator(){
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while(true){
              String read;
              try{
                read = br.readLine();
              }catch(IOException e){
                read = null;
              }
              if(read != null){
                inputLine.add(read);
              }else{
                break;
              }
            }
            max = inputLine.size();
          }
          public boolean hasNext(){return (index < max);}
          public String next(){
            if(hasNext()){
              String returnStr = inputLine.get(index);
              index++;
              return returnStr;
            }else{
              throw new IndexOutOfBoundsException("これ以上入力はないよ。");
            }
          }
        }

        static InputIterator ii = new InputIterator();
        static void myout(Object t){System.out.println(t);}
        static void myerr(Object t){System.err.println(t);}
        static String next(){return ii.next();}
        static int nextInt(){return Integer.parseInt(next());}
        static long nextLong(){return Long.parseLong(next());}
        static String[] nextStrArray(){return next().split(" ");}
        static ArrayList<Integer> nextIntArray(){
          ArrayList<Integer> ret = new ArrayList<Integer>();
          String[] input = nextStrArray();
          for(int i = 0; i < input.length; i++){
            ret.add(Integer.parseInt(input[i]));
          }
          return ret;
        }
        static ArrayList<Long> nextLongArray(){
          ArrayList<Long> ret = new ArrayList<Long>();
          String[] input = nextStrArray();
          for(int i = 0; i < input.length; i++){
            ret.add(Long.parseLong(input[i]));
          }
          return ret;
        }
        static char[] nextCharArray(){return mySplit(next());}
        static char[] mySplit(String str){return str.toCharArray();}
        static String kaigyoToStr(String[] list){return String.join("\n",list);}
        static String kaigyoToStr(ArrayList<String> list){return String.join("\n",list);}
        static String hanSpToStr(String[] list){return String.join(" ",list);}
        static String hanSpToStr(ArrayList<String> list){return String.join(" ",list);}
        public static void main(String[] args){
          int t = nextInt();
	for(int i = 0; i < t; i++){
		ArrayList<Long> tmp = nextLongArray();
		long N = tmp.get(0);
		long K = tmp.get(1);
		LinkedList<Long> list = getDivisorList(N);
		long last = list.get(1);
      if(isPrime(N)){
        N += N;
        K--;
        list = getDivisorList(N);
        last = list.get(1);
      }
      N += last * K;

		myout(N);
	}
        }
        //Method addition frame start
public static LinkedList<Long> getDivisorList(long val){
        LinkedList<Long> list = new LinkedList<Long>();
        for(long i = 1; i * i <= val; i++){
                if(val % i == 0){
                        list.add(i);
                        if(i * i != val){
                                list.add(val / i);
                        }
                }
        }
        Collections.sort(list, Comparator.naturalOrder());
        return list;
}
  static boolean isPrime(long val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        double root = Math.floor(Math.sqrt(val));
        for(long i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
        //Method addition frame end
}


import java.util.*;
import java.io.*;
public class Main {
        static public class InputIterator{
          ArrayList<String> inputLine = new ArrayList<String>(1024);
          int index = 0;
          int max;
          InputIterator(){
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while(true){
              String read;
              try{
                read = br.readLine();
              }catch(IOException e){
                read = null;
              }
              if(read != null){
                inputLine.add(read);
              }else{
                break;
              }
            }
            max = inputLine.size();
          }
          public boolean hasNext(){return (index < max);}
          public String next(){
            if(hasNext()){
              String returnStr = inputLine.get(index);
              index++;
              return returnStr;
            }else{
              throw new IndexOutOfBoundsException("これ以上入力はないよ。");
            }
          }
        }

        static InputIterator ii = new InputIterator();
        static void myout(Object t){System.out.println(t);}
        static void myerr(Object t){System.err.println(t);}
        static String next(){return ii.next();}
        static int nextInt(){return Integer.parseInt(next());}
        static long nextLong(){return Long.parseLong(next());}
        static String[] nextStrArray(){return next().split(" ");}
        static ArrayList<Integer> nextIntArray(){
          ArrayList<Integer> ret = new ArrayList<Integer>();
          String[] input = nextStrArray();
          for(int i = 0; i < input.length; i++){
            ret.add(Integer.parseInt(input[i]));
          }
          return ret;
        }
        static ArrayList<Long> nextLongArray(){
          ArrayList<Long> ret = new ArrayList<Long>();
          String[] input = nextStrArray();
          for(int i = 0; i < input.length; i++){
            ret.add(Long.parseLong(input[i]));
          }
          return ret;
        }
        static char[] nextCharArray(){return mySplit(next());}
        static char[] mySplit(String str){return str.toCharArray();}
        static String kaigyoToStr(String[] list){return String.join("\n",list);}
        static String kaigyoToStr(ArrayList<String> list){return String.join("\n",list);}
        static String hanSpToStr(String[] list){return String.join(" ",list);}
        static String hanSpToStr(ArrayList<String> list){return String.join(" ",list);}
        public static void main(String[] args){
          int t = nextInt();
	for(int i = 0; i < t; i++){
		ArrayList<Integer> tmp = nextIntArray();
		int N = tmp.get(0);
		int K = tmp.get(1);
      long output = 0;
      output += N;
		LinkedList<Long> list = getDivisorList(N);
		long last = list.get(1);
		while(isPrime(N) && K > 0){
			N += N;
			K--;
			list = getDivisorList(N);
			last = list.get(1);
		}
		N += last * K;
		myout(N);
	}
        }
        //Method addition frame start
public static LinkedList<Long> getDivisorList(long val){
        LinkedList<Long> list = new LinkedList<Long>();
        for(long i = 1; i * i <= val; i++){
                if(val % i == 0){
                        list.add(i);
                        if(i * i != val){
                                list.add(val / i);
                        }
                }
        }
        Collections.sort(list, Comparator.naturalOrder());
        return list;
}
  static boolean isPrime(long val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        double root = Math.floor(Math.sqrt(val));
        for(long i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
        //Method addition frame end
}


import java.util.*;

public class WaterMelon {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        int cases = Integer.parseInt(reader.nextLine());

        for (int i = 0; i < cases; i++) {
            String[] input = reader.nextLine().split(" ");
            int n = Integer.parseInt(input[0]);
            int k = Integer.parseInt(input[1]);
            int divisor=divisor(n);

                n =n+divisor+(k-1)*2;

            System.out.println(n);

        }

    }

    static int divisor(int in) {

        int divisor = 1;
        int rest = 0;
        if (in % 2 == 0) {
            divisor = 2;
        } else {

            do {
                divisor=divisor+2;

                rest = in % divisor;

            } while (rest != 0);
        }

        return divisor;
    }
}


import java.util.*;

public class WaterMelon {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        int cases = Integer.parseInt(reader.nextLine());

        for (int i = 0; i < cases; i++) {
            String[] input = reader.nextLine().split(" ");
            int n = Integer.parseInt(input[0]);
            int k = Integer.parseInt(input[1]);
            for (int j = 0; j < k; j++) {
                n=divisor(n)+n;
            }

            System.out.println(n);

        }

    }

    static int divisor(int in) {

        int divisor = 1;
        int rest = 0;
        do {
            divisor++;
            rest = in % divisor;
        } while (rest != 0);

        return divisor;
    }
}


import java.util.*;

public class WaterMelon {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        int cases = Integer.parseInt(reader.nextLine());

        for (int i = 0; i < cases; i++) {
            String[] input = reader.nextLine().split(" ");
            int n = Integer.parseInt(input[0]);
            int k = Integer.parseInt(input[1]);
            for (int j = 0; j < k; j++) {
                n = divisor(n) + n;
            }

            System.out.println(n);

        }

    }

    static int divisor(int in) {

        int divisor = 1;
        int rest = 0;
        if (in % 2 == 0) {
            divisor = 2;
        } else {

            do {
                divisor=divisor+2;

                rest = in % divisor;

            } while (rest != 0);
        }

        return divisor;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test {
    public static void main(String[] args) throws IOException {
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String test_numS=bf.readLine();
        int test_num=Integer.parseInt(test_numS);
        while(test_num>0){
            String NandK=bf.readLine();
            String nk[]=NandK.split(" ");
            int n=Integer.parseInt(nk[0]);
            int k=Integer.parseInt(nk[1]);

            solve(n,k);
            test_num--;
        }

    }
    public static void solve(int n,int k){
        //long out=n;
        while (k>0){
            if (n%2==0){
                n+=2*k;
                k=0;
                continue;
            }else {
                for (int i = 3; i <=n ; i+=2) {
                    if (n%i==0){
                        n+=i;
                        k--;
                        break;
                    }
                }
            }
        }
        System.out.println(n);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Test {
    public static void main(String[] args) throws IOException {
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String test_numS=bf.readLine();
        int test_num=Integer.parseInt(test_numS);
        while(test_num>0){
            String NandK=bf.readLine();
            String nk[]=NandK.split(" ");
            int n=Integer.parseInt(nk[0]);
            int k=Integer.parseInt(nk[1]);

            solve(n,k);
            test_num--;
        }

    }
    public static void solve(int n,int k){
        //long out=n;
        while (k>0){
            if (n%2==0){
                n+=2;
                k--;
                continue;
            }else {
                for (int i = 3; i <=n ; i+=2) {
                    if (n%i==0){
                        n+=i;
                        k--;
                        break;
                    }
                }
            }
        }
        System.out.println(n);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test {
    public static void main(String[] args) throws IOException {
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String test_numS=bf.readLine();
        int test_num=Integer.parseInt(test_numS);
        while(test_num>0){
            String NandK=bf.readLine();
            String nk[]=NandK.split(" ");
            int n=Integer.parseInt(nk[0]);
            int k=Integer.parseInt(nk[1]);

            solve(n,k);
            test_num--;
        }

    }
    public static void solve(int n,int k){
        //long out=n;
        while (k>0){
            if (n%2==0){
                n+=2*k;
                k=0;
                continue;
            }else {
                for (int i = 3; i <=n ; i+=2) {
                    if (n%i==0){
                        n+=i*(k-1);
                        k=0;
                        break;
                    }
                }
            }
        }
        System.out.println(n);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Test {
    public static void main(String[] args) throws IOException {
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String test_numS=bf.readLine();
        int test_num=Integer.parseInt(test_numS);
        while(test_num>0){
            String NandK=bf.readLine();
            String nk[]=NandK.split(" ");
            int n=Integer.parseInt(nk[0]);
            int k=Integer.parseInt(nk[1]);

            solve(n,k);
            test_num--;
        }

    }
    public static void solve(int n,int k){
        long out=n;
        while (k>0){
            if (out%2==0){
                out+=2;
                k--;
                continue;
            }else {
                for (long i = 3; i <=out ; i+=2) {
                    if (out%i==0){
                        out+=i;
                        k--;
                        break;
                    }
                }
            }
        }
        System.out.println(n);
    }
}


//1350A-未完成
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Orac_and_Factors {
    public static void main(String[] args) throws IOException {
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String test_numS=bf.readLine();
        int test_num=Integer.parseInt(test_numS);
        while(test_num>0){
            String NandK=bf.readLine();
            String nk[]=NandK.split(" ");
            int n=Integer.parseInt(nk[0]);
            int k=Integer.parseInt(nk[1]);

            solve(n,k);
            test_num--;
        }

    }
    public static void solve(int n,int k){
        while (k>0){
            if (n%2==0){
                n+=2*k;//很关键，节省很多时间，当该数位偶数时，直接加上2*k，因为加完2后他仍未偶数加2
                k=0;
                continue;
            }else {
                for (int i = 3; i <=n ; i+=2) {//为奇数从3开始除，每次加2
                    if (n%i==0){
                        n+=i;
                        k--;
                        break;
                    }
                }
            }
        }
        System.out.println(n);
    }
}


//1350A
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Orac_and_Factors {
    public static void main(String[] args) {
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String amountS=null;
        try{
            amountS=bf.readLine();
        }catch (IOException e){
            e.printStackTrace();
        }
        int amountI=Integer.parseInt(amountS);
        while(amountI>0){
            String valueS=null;
            try{
                valueS=bf.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }
             String []value=valueS.split(" ");
            int first_num=Integer.parseInt(value[0]);
            int times=Integer.parseInt(value[1]);
            int min_divisor=1;
            while(times>0){
                for (int i = 2; i <= first_num; i++) {
                    if(first_num%i==0){
                        min_divisor=i;
                        break;
                    }
                }
                first_num+=min_divisor;
                times--;
                if(times==0){
                    System.out.println(first_num);
                }
            }
            amountI--;
        }
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = Integer.parseInt(input.nextLine());
        String[] numbers;
        for(int i = 0;i < t;i++) {
            numbers = input.nextLine().split("\\s");
            int n = Integer.parseInt(numbers[0]);
            int k = Integer.parseInt(numbers[1]);
            int divisor = function(n);
            n = n + divisor + (k - 1)*2;
            System.out.println(n);
        }

    }

    public static int function(int n) {
        for(int i = 2;i <= n;i++) {
            if(i >= n/2){
                return n;
            }
            if(n % i == 0 ){
                return i;
            }
        }
        return -1;
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = Integer.parseInt(input.nextLine());
        String[] numbers;
        for(int i = 0;i < t;i++) {
            numbers = input.nextLine().split("\\s");
            int n = Integer.parseInt(numbers[0]);
            int k = Integer.parseInt(numbers[1]);
            int divisor = function(n);
            n = n + divisor + (k - 1)*2;
            System.out.println(n);
        }

    }

    public static int function(int n) {
        for(int i = 2;i <= n;i++) {
            if(n % i == 0 ){
                return i;
            }
        }
        return -1;
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = Integer.parseInt(input.nextLine());
        String[] numbers;
        for(int i = 0;i < t;i++) {
            numbers = input.nextLine().split("\\s");
            int n = Integer.parseInt(numbers[0]);
            int k = Integer.parseInt(numbers[1]);
            for(int j = 0;j < k;j++){
                n = n + function(n);
            }
            System.out.println(n);
        }

    }

    public static int function(int n) {
        for(int i = 2;i <= n;i++) {
            if(n % i == 0 ){
                return i;
            }
        }
        return -1;
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = Integer.parseInt(input.nextLine());
        String[] numbers;
        for(int i = 0;i < t;i++) {
            numbers = input.nextLine().split("\\s");
            int n = Integer.parseInt(numbers[0]);
            long k = Long.parseLong(numbers[1]);
            for(int j = 0;j < k;j++){
                n = n + function(n);
            }
            System.out.println(n);
        }

    }

    public static int function(int n) {
        for(int i = 2;i <= n;i++) {
            if(n % i == 0 ){
                return i;
            }
        }
        return -1;
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = Integer.parseInt(input.nextLine());
        String[] numbers;
        for(int i = 0;i < t;i++) {
            numbers = input.nextLine().split("\\s");
            int n = Integer.parseInt(numbers[0]);
            long k = Long.parseLong(numbers[1]);
            for(int j = 0;j < k;j++){
                n = n + function(n);
            }
            System.out.println(n);
        }

    }

    public static int function(int n) {
        for(int i = 2;i <= n;i++) {
            if(i >= n/2){
                return n;
            }
            if(n % i == 0 ){
                return i;
            }
        }
        return -1;
    }
}


import java.util.*;

public class MainClass {

	static int smallest(long n) {

		if(n % 2 == 0) {
			return 2;
		}
		for(int i = 3 ; i*i <= n ; i+=2) {
			if(n % i == 0) {
				return i;
			}
		}
		return n;
	}

	public static void main(String [] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-- >0) {
			long n = sc.nextInt();
			long k = sc.nextInt();
			while(k-- >0) {
				n = n + smallest(n);
			}
			System.out.println(n);
		}
	}
}


import java.util.*;

public class Main{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- >0){
            int n = sc.nextInt();
            int k = sc.nextInt();

            for(int i=2 ; i<=n ; i++){
                if(n%i == 0){
                    n=n+i;
                    break;
                }
            }
            n=n+2*(k-1);
            System.out.println(n);
        }
    }
}


import java.util.*;

public class MainClass {

	static int smallest(int n) {

		if(n % 2 == 0) {
			return 2;
		}
		for(int i = 3 ; i*i <= n ; i+=2) {
			if(n % i == 0) {
				return i;
			}
		}
		return n;
	}

	public static void main(String [] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-- >0) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			while(k-- >0) {
				n = n + smallest(n);
			}
			System.out.println(n);
		}
	}
}