import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

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

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

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

        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();
        }
    }

    static class Words {
        String word;
        int cost;

        public Words(String word) {
            this.word = word;
        }
    }

    static class Node {
        int key;
        int edgeweight;
        int height;

        public Node(int key, int edgeweight) {
            this.key = key;
            this.edgeweight = edgeweight;
        }
    }

    static class Graph {
        int vertices;
        ArrayList<ArrayList<Node>> al;

        public Graph(int vertices) {
            this.vertices = vertices;
            al = new ArrayList<>(vertices);
            for (int i = 0; i < vertices; i++) {
                al.add(new ArrayList<Node>());
            }
        }

        public static void addEdgeUndirected(ArrayList<ArrayList<Node>> al, int source, int destination, int weight) {
            al.get(source).add(new Node(destination, weight));
            al.get(destination).add(new Node(destination, weight));
        }

        /* public static int bfs(ArrayList<ArrayList<Node>> al, int v, int root) {
             //here root means the starting vertex for bfs
             int count = 1;
             boolean[] visited = new boolean[v];
             Queue<Integer> q = new LinkedList<>();
             visited[root] = true;
             q.add(root);
             while (!q.isEmpty()) {
                 int u = q.poll();
                 for (int i = 0; i < al.get(u).size(); i++) {
                     if (!visited[al.get(u).get(i).key]) {
                         visited[al.get(u).get(i).key] = true;
                         q.add(al.get(u).get(i).key);
                         count++;
                     }
                 }
             }
             return count;
         }*/
        public static void bfs(ArrayList<ArrayList<Node>> al, int v, int root) {
            //here root means the starting vertex for bfs
            boolean[] visited = new boolean[v];
            Queue<Integer> q = new LinkedList<>();
            visited[root] = true;
            q.add(root);
            while (!q.isEmpty()) {
                int u = q.poll();
                System.out.print(u + " ");
                for (int i = 0; i < al.get(u).size(); i++) {
                    if (!visited[al.get(u).get(i).key]) {
                        visited[al.get(u).get(i).key] = true;
                        q.add(al.get(u).get(i).key);
                    }
                }
            }
        }

    }

    static int countDigit(long n) {
        return (int) Math.floor(Math.log10(n) + 1);
    }

    public static void main(String[] args) throws IOException {
        Reader r = new Reader();
        int t = r.nextInt();
        while (t-- > 0) {
            int n = r.nextInt();
            int k = r.nextInt();
            while(k-->0){
                if(n%2==0) n+=2;
                else if(n%3==0) n+=3;
                else if(n%5==0) n +=5;
                else if(n%7==0) n+=7;
                else n+=9;
            }
            System.out.println(n);
        }
    }
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

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

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

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

        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();
        }
    }

    static class Words {
        String word;
        int cost;

        public Words(String word) {
            this.word = word;
        }
    }

    static class Node {
        int key;
        int edgeweight;
        int height;

        public Node(int key, int edgeweight) {
            this.key = key;
            this.edgeweight = edgeweight;
        }
    }

    static class Graph {
        int vertices;
        ArrayList<ArrayList<Node>> al;

        public Graph(int vertices) {
            this.vertices = vertices;
            al = new ArrayList<>(vertices);
            for (int i = 0; i < vertices; i++) {
                al.add(new ArrayList<Node>());
            }
        }

        public static void addEdgeUndirected(ArrayList<ArrayList<Node>> al, int source, int destination, int weight) {
            al.get(source).add(new Node(destination, weight));
            al.get(destination).add(new Node(destination, weight));
        }

        /* public static int bfs(ArrayList<ArrayList<Node>> al, int v, int root) {
             //here root means the starting vertex for bfs
             int count = 1;
             boolean[] visited = new boolean[v];
             Queue<Integer> q = new LinkedList<>();
             visited[root] = true;
             q.add(root);
             while (!q.isEmpty()) {
                 int u = q.poll();
                 for (int i = 0; i < al.get(u).size(); i++) {
                     if (!visited[al.get(u).get(i).key]) {
                         visited[al.get(u).get(i).key] = true;
                         q.add(al.get(u).get(i).key);
                         count++;
                     }
                 }
             }
             return count;
         }*/
        public static void bfs(ArrayList<ArrayList<Node>> al, int v, int root) {
            //here root means the starting vertex for bfs
            boolean[] visited = new boolean[v];
            Queue<Integer> q = new LinkedList<>();
            visited[root] = true;
            q.add(root);
            while (!q.isEmpty()) {
                int u = q.poll();
                System.out.print(u + " ");
                for (int i = 0; i < al.get(u).size(); i++) {
                    if (!visited[al.get(u).get(i).key]) {
                        visited[al.get(u).get(i).key] = true;
                        q.add(al.get(u).get(i).key);
                    }
                }
            }
        }

    }

    static int countDigit(long n) {
        return (int) Math.floor(Math.log10(n) + 1);
    }

    public static void main(String[] args) throws IOException {
        Reader r = new Reader();
        int t = r.nextInt();
        while (t-- > 0) {
            int n = r.nextInt();
            int k = r.nextInt();
            boolean flag = false;
                if(n%2==0){
                    n+=2*k;
                }else{
                    if(n%3==0) n+=3;
                    else if(n%5==0) n+=5;
                    else if(n%7==0) n+=7;
                    else n+=9;
                    flag = true;
                }
                if(flag) n+=(k-1)*2;
            System.out.println(n);

        }
    }
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

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

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

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

        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();
        }
    }

    static class Words {
        String word;
        int cost;

        public Words(String word) {
            this.word = word;
        }
    }

    static class Node {
        int key;
        int edgeweight;
        int height;

        public Node(int key, int edgeweight) {
            this.key = key;
            this.edgeweight = edgeweight;
        }
    }

    static class Graph {
        int vertices;
        ArrayList<ArrayList<Node>> al;

        public Graph(int vertices) {
            this.vertices = vertices;
            al = new ArrayList<>(vertices);
            for (int i = 0; i < vertices; i++) {
                al.add(new ArrayList<Node>());
            }
        }

        public static void addEdgeUndirected(ArrayList<ArrayList<Node>> al, int source, int destination, int weight) {
            al.get(source).add(new Node(destination, weight));
            al.get(destination).add(new Node(destination, weight));
        }

        /* public static int bfs(ArrayList<ArrayList<Node>> al, int v, int root) {
             //here root means the starting vertex for bfs
             int count = 1;
             boolean[] visited = new boolean[v];
             Queue<Integer> q = new LinkedList<>();
             visited[root] = true;
             q.add(root);
             while (!q.isEmpty()) {
                 int u = q.poll();
                 for (int i = 0; i < al.get(u).size(); i++) {
                     if (!visited[al.get(u).get(i).key]) {
                         visited[al.get(u).get(i).key] = true;
                         q.add(al.get(u).get(i).key);
                         count++;
                     }
                 }
             }
             return count;
         }*/
        public static void bfs(ArrayList<ArrayList<Node>> al, int v, int root) {
            //here root means the starting vertex for bfs
            boolean[] visited = new boolean[v];
            Queue<Integer> q = new LinkedList<>();
            visited[root] = true;
            q.add(root);
            while (!q.isEmpty()) {
                int u = q.poll();
                System.out.print(u + " ");
                for (int i = 0; i < al.get(u).size(); i++) {
                    if (!visited[al.get(u).get(i).key]) {
                        visited[al.get(u).get(i).key] = true;
                        q.add(al.get(u).get(i).key);
                    }
                }
            }
        }

    }

    static int countDigit(long n) {
        return (int) Math.floor(Math.log10(n) + 1);
    }

    public static void main(String[] args) throws IOException {
        Reader r = new Reader();
        int t = r.nextInt();
        while (t-- > 0) {
            int n = r.nextInt();
            int k = r.nextInt();
            boolean flag = false;
                if(n%2==0){
                    n+=2*k;
                }else{
                    for(int i=3;i<=n;i+=2){
                        if(n%i==0){
                            n+=i;
                            break;
                        }
                    }
                    flag = true;
                }
                if(flag) n+=(k-1)*2;
            System.out.println(n);

        }
    }
}


import java.util.Scanner;

public class Factors {

    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        int cases = scanner.nextInt();

        for (int c = 1; c <= cases; c++) {
            solve();
        }

    }

    private static void solve() {

        long n = scanner.nextInt();
        long k = scanner.nextInt();

        long d = n;
        for(int i=2;i<=Math.sqrt(n);i++){
            if(n%i==0){
                d = i;
            }
        }

        System.out.println(n+d+(k-1)*2);
    }
}


import java.util.Scanner;

public class Factors {

    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        int cases = scanner.nextInt();

        for (int c = 1; c <= cases; c++) {
            solve();
        }
    }

    private static void solve() {

        long n = scanner.nextInt();
        long k = scanner.nextInt();

        long d = n;
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                d = i;
                break;
            }
        }

        System.out.println(n + d + (k - 1) * Math.min(2, d));
    }
}


import java.util.Scanner;

public class Factors {

    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        int cases = scanner.nextInt();

        for (int c = 1; c <= cases; c++) {
            solve();
        }

    }

    private static void solve() {

        int n = scanner.nextInt();
        int k = scanner.nextInt();

        int d = n;
        for(int i=2;i<=Math.sqrt(n);i++){
            if(n%i==0){
                d = i;
            }
        }

        System.out.println(n+d+(k-1)*2);
    }
}


import java.util.Scanner;

public class Factors {

    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        int cases = scanner.nextInt();

        for (int c = 1; c <= cases; c++) {
            solve();
        }
    }

    private static void solve() {

        long n = scanner.nextInt();
        long k = scanner.nextInt();

        long d = n;
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                d = i;
            }
        }

        System.out.println(n + d + (k - 1) * Math.min(2, d));
    }
}


/**
 * @author egaeus
 * @mail sebegaeusprogram@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CFA {
    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int T = parseInt(in.readLine());
        for (int t = 0; t < T; t++) {
            StringTokenizer st = new StringTokenizer(in.readLine());
            int N = parseInt(st.nextToken()), K = parseInt(st.nextToken());
            int D = f(N);
            while (D > 2) {
                N += D;
                D = f(N);
                K--;
            }
            System.out.println(N + 2 * K);
        }
    }

    static int f(int a) {
        for (int i = 2; i <= Math.sqrt(a); i++)
            if (a % i == 0)
                return i;
        return a;
    }
}


/**
 * @author egaeus
 * @mail sebegaeusprogram@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CFA {
    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int T = parseInt(in.readLine());
        int[] div = new int[1000001];
        for (int i = 2; i < div.length; i++)
            div[i] = f(i);
        for (int t = 0; t < T; t++) {
            StringTokenizer st = new StringTokenizer(in.readLine());
            int N = parseInt(st.nextToken()), K = parseInt(st.nextToken());
            int[] visited = new int[1000001];
            Arrays.fill(visited, -1);
            visited[N] = 0;
            for (int i = 1; i <= K; i++) {
                N += div[N];
                if (visited[N] != -1) {
                    Arrays.fill(visited, -1);
                    K = K % i;
                    i = 1;
                }
                else
                    visited[N] = i;
            }
            System.out.println(N);
        }
    }

    static int f(int a) {
        for (int i = 2; i <= Math.sqrt(a); i++)
            if (a % i == 0)
                return i;
        return a;
    }
}


/**
 * @author egaeus
 * @mail sebegaeusprogram@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CFA {
    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int T = parseInt(in.readLine());
        int[] div = new int[1000001];
        for (int t = 0; t < T; t++) {
            StringTokenizer st = new StringTokenizer(in.readLine());
            int N = parseInt(st.nextToken()), K = parseInt(st.nextToken());
            int[] visited = new int[1000001];
            Arrays.fill(visited, -1);
            visited[N] = 0;
            for (int i = 1; i <= K; i++) {
                N += div[N];
                if (visited[N] != -1) {
                    Arrays.fill(visited, -1);
                    K = K % i;
                    i = 1;
                }
                else
                    visited[N] = i;
            }
            System.out.println(N);
        }
    }

    static int f(int a) {
        for (int i = 2; i <= Math.sqrt(a); i++)
            if (a % i == 0)
                return i;
        return a;
    }
}


/**
 * @author egaeus
 * @mail sebegaeusprogram@gmail.com
 * @veredict
 * @url
 * @category
 * @date
 **/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class CFA {
    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int T = parseInt(in.readLine());
        int[] div = new int[1000001];
        for (int i = 2; i < div.length; i++)
            div[i] = f(i);
        for (int t = 0; t < T; t++) {
            StringTokenizer st = new StringTokenizer(in.readLine());
            int N = parseInt(st.nextToken()), K = parseInt(st.nextToken());
            int D = div[N];
            while (D > 2) {
                N += D;
                D = div[N];
                K--;
            }
            System.out.println(N + 2 * K);
        }
    }

    static int f(int a) {
        for (int i = 2; i <= Math.sqrt(a); i++)
            if (a % i == 0)
                return i;
        return a;
    }
}


import java.util.Scanner;

public class OracAndFactors {
	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);
		int b = a.nextInt();
		int [] fin = new int [b];
		for(int c = 0; c < b; c++) {
			int e = a.nextInt();
			int g = a.nextInt();
			for(int f = 0; f < g; f ++) {
				int d = 2;
				while(e%d != 0) {
					d++;
				}
				e = e + d;
			}
			fin[c] = e;
		}
		for(int c = 0; c < b; c++) {
			System.out.println(fin[c]);
		}
	}
}


import java.util.Scanner;

public class OracAndFactors {
	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);
		int b = a.nextInt();
		int [] fin = new int [b];
		for(int c = 0; c < b; c++) {
			int e = a.nextInt();
			int g = a.nextInt();
			int d=2;
			while(e%d != 0) {
				d++;
			}
			e = e + d + ((g-1)*2);
			fin[c] = e;
		}
		for(int c = 0; c < b; c++) {
			System.out.println(fin[c]);
		}
	}
}


package Easy;
import java.util.Scanner;

public class OracAndFactors {
	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);
		int b = a.nextInt();
		int [] fin = new int [b];
		for(int c = 0; c < b; c++) {
			int e = a.nextInt();
			int g = a.nextInt();
			int d=2;
			while(e%d != 0) {
				d++;
			}
			e = e + d + ((g-1)*2);
			fin[c] = e;
		}
		for(int c = 0; c < b; c++) {
			System.out.println(fin[c]);
		}
	}
}


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

public class Solution{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int t = sc.nextInt();
		for(int i = 0; i < t; i++){
			int n = sc.nextInt();
			int k = sc.nextInt();
			int current = n;
			int func = 0;
			if(current % 2 == 0){
				func = 2;
				current = k * 2 + n;
			} else if(current%3 == 0){
				func = 3;
				current = 3*(k-1) + n;
			} else if(current%5 == 0){
				func = 5;
				current = 5*(k)+n;
			} else if(current%7 == 0){
				func = 7;
				current = 7*(k-1)+n;
			} else{
				func = current;
			}
			// for(int j = 0; j < k; j++){
			// 	if(current % 2 == 0){
			// 		func = 2;
			// 	} else if(current%3 == 0){
			// 		func = 3;
			// 	} else if(current%5 == 0){
			// 		func = 5;
			// 	} else if(current%7 == 0){
			// 		func = 7;
			// 	} else{
			// 		func = current;
			// 	}

			// 	current = func + current;
			// }

			System.out.println(current);
		}
	}
}


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

public class Solution{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int t = sc.nextInt();
		for(int i = 0; i < t; i++){
			int n = sc.nextInt();
			int k = sc.nextInt();
			int current = 0;
			if(n % 2 == 0){
				current = k * 2 + n;
			} else{
				int p = 0;
				for(int j = n; j >= 2; j--){
					if(n % j == 0){
						p = j;
					}
				}
				current = 2*(k-1) + p + n;
			} /* else if(current%3 == 0){
				current = 2*(k-1) + n + 3;
			} else if(current%5 == 0){
				current = 2*(k-1)+ n + 5;
			} else if(current%7 == 0){
				current = 2*(k-1)+ n + 7;
			} else{
				current = 2*(k-1)+n+n;
			} */ //bruh

			System.out.println(current);
		}
	}
}


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

public class Solution{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int t = sc.nextInt();
		for(int i = 0; i < t; i++){
			int n = sc.nextInt();
			int k = sc.nextInt();
			int current = n;
			int func = 0;
			if(current % 2 == 0){
				func = 2;
				current = k * 2 + n;
			} else if(current%3 == 0){
				func = 3;
				current = 2*(k-1) + n + 3;
			} else if(current%5 == 0){
				func = 5;
				current = 2*(k-1)+ n + 5;
			} else if(current%7 == 0){
				func = 7;
				current = 2*(k-1)+ n + 7;
			} else{
				func = 2*(k-1)+n+n;
			}
			// for(int j = 0; j < k; j++){
			// 	if(current % 2 == 0){
			// 		func = 2;
			// 	} else if(current%3 == 0){
			// 		func = 3;
			// 	} else if(current%5 == 0){
			// 		func = 5;
			// 	} else if(current%7 == 0){
			// 		func = 7;
			// 	} else{
			// 		func = current;
			// 	}

			// 	current = func + current;
			// }

			System.out.println(current);
		}
	}
}


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

public class Solution{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int t = sc.nextInt();
		for(int i = 0; i < t; i++){
			int n = sc.nextInt();
			int k = sc.nextInt();
			int current = n;
			int func = 0;
			for(int j = 0; j < k; j++){
				if(current % 2 == 0){
					func = 2;
				} else if(current%3 == 0){
					func = 3;
				} else if(current%5 == 0){
					func = 5;
				} else if(current%7 == 0){
					func = 7;
				} else{
					func = current;
				}

				current = func + current;
			}

			System.out.println(current);
		}
	}
}


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

public class Solution{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int t = sc.nextInt();
		for(int i = 0; i < t; i++){
			int n = sc.nextInt();
			int k = sc.nextInt();
			int current = n;
			if(current % 2 == 0){
				current = k * 2 + n;
			} else if(current%3 == 0){
				current = 2*(k-1) + n + 3;
			} else if(current%5 == 0){
				current = 2*(k-1)+ n + 5;
			} else if(current%7 == 0){
				current = 2*(k-1)+ n + 7;
			} else{
				current = 2*(k-1)+n+n;
			}
			// for(int j = 0; j < k; j++){
			// 	if(current % 2 == 0){
			// 		func = 2;
			// 	} else if(current%3 == 0){
			// 		func = 3;
			// 	} else if(current%5 == 0){
			// 		func = 5;
			// 	} else if(current%7 == 0){
			// 		func = 7;
			// 	} else{
			// 		func = current;
			// 	}

			// 	current = func + current;
			// }

			System.out.println(current);
		}
	}
}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main implements Runnable  {
    boolean multiple = true;

    void solve() throws Exception {
        long n = sc.nextLong();
        long k = sc.nextLong();
        if (n % 2 != 0) {
            boolean bool = false;
            for (long i = 3; i <= sqrt(n); i++) {
                //System.out.println(len);
                if (n % i == 0) {
                    n += i;
                    bool = true;
                    break;
                }
            }
            if (!bool) {
                n += n;
            }
            k --;
        }
        n += 2*k;
        System.out.println(n);
    }

    @Override
    public void run() {
        try
        {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            sc = new FastScanner(in);
            if (multiple)
            {
                int q = sc.nextInt();
                for (int i = 0; i < q; i++)
                    solve();
            }
            else
                solve();
        }
        catch (Throwable uncaught)
        {
            Main.uncaught = uncaught;
        }
        finally
        {
            out.close();
        }
    }
    public static void main(String[] args) throws Throwable  {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        if (Main.uncaught != null) {
            throw Main.uncaught;
        }
    }
    static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out;
}
class FastScanner  {
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in)
    {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main implements Runnable  {
    boolean multiple = true;

    void solve() throws Exception {
        long n = sc.nextLong();
        long k = sc.nextLong();
        boolean bool = false;
        for (long j = 0; j < k; j++) {
            if(n%2 == 0) {
                n += 2;
            } else {
                for (long i = 3; i <= sqrt(n); i++) {
                    //System.out.println(len);
                    if (n % i == 0) {
                        n += i;
                        bool = true;
                        break;
                    }
                }
                if (!bool) {
                    n += n;
                }
                bool = false;
            }
        }
        System.out.println(n);
    }

    @Override
    public void run() {
        try
        {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            sc = new FastScanner(in);
            if (multiple)
            {
                int q = sc.nextInt();
                for (int i = 0; i < q; i++)
                    solve();
            }
            else
                solve();
        }
        catch (Throwable uncaught)
        {
            Main.uncaught = uncaught;
        }
        finally
        {
            out.close();
        }
    }
    public static void main(String[] args) throws Throwable  {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        if (Main.uncaught != null) {
            throw Main.uncaught;
        }
    }
    static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out;
}
class FastScanner  {
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in)
    {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main implements Runnable  {
    boolean multiple = true;

    void solve() throws Exception {
        int n = sc.nextInt();
        int k = sc.nextInt();
        boolean bool = false;
        for (int j = 0; j < k; j++) {
            if(n%2 == 0) {
                n += 2;
            } else {
                for (int i = 2; i <= sqrt(n); i++) {
                    //System.out.println(len);
                    if (n % i == 0) {
                        n += i;
                        bool = true;
                        break;
                    }
                }
                if (!bool) {
                    n += n;
                }
                bool = false;
            }
        }
        System.out.println(n);
    }

    @Override
    public void run() {
        try
        {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            sc = new FastScanner(in);
            if (multiple)
            {
                int q = sc.nextInt();
                for (int i = 0; i < q; i++)
                    solve();
            }
            else
                solve();
        }
        catch (Throwable uncaught)
        {
            Main.uncaught = uncaught;
        }
        finally
        {
            out.close();
        }
    }
    public static void main(String[] args) throws Throwable  {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        if (Main.uncaught != null) {
            throw Main.uncaught;
        }
    }
    static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out;
}
class FastScanner  {
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in)
    {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main implements Runnable  {
    boolean multiple = true;

    void solve() throws Exception {
        int n = sc.nextInt();
        int k = sc.nextInt();
        boolean bool = false;
        for (int j = 0; j < k; j++) {
            if(n%2 == 0) {
                n += 2;
            } else {
                int len = (int) sqrt(n) + 1;
                for (int i = 2; i < len; i++) {
                    //System.out.println(len);
                    if (n % i == 0) {
                        n += i;
                        bool = true;
                        break;
                    }
                }
                if (!bool) {
                    n += n;
                    bool = false;
                }
            }
        }
        System.out.println(n);
    }

    @Override
    public void run() {
        try
        {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            sc = new FastScanner(in);
            if (multiple)
            {
                int q = sc.nextInt();
                for (int i = 0; i < q; i++)
                    solve();
            }
            else
                solve();
        }
        catch (Throwable uncaught)
        {
            Main.uncaught = uncaught;
        }
        finally
        {
            out.close();
        }
    }
    public static void main(String[] args) throws Throwable  {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        if (Main.uncaught != null) {
            throw Main.uncaught;
        }
    }
    static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out;
}
class FastScanner  {
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in)
    {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main implements Runnable  {
    boolean multiple = true;

    void solve() throws Exception {
        int n = sc.nextInt();
        int k = sc.nextInt();
        boolean bool = false;
        for (int j = 0; j < k; j++) {
            int len = (int)sqrt(n)+1;
            for (int i = 2; i < len; i++) {
                //System.out.println(len);
                if (n%i == 0) {
                    n += i;
                    bool = true;
                    break;
                }
            }
            if (!bool) {
                n += n;
                bool = false;
            }
        }
        System.out.println(n);
    }

    @Override
    public void run() {
        try
        {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            sc = new FastScanner(in);
            if (multiple)
            {
                int q = sc.nextInt();
                for (int i = 0; i < q; i++)
                    solve();
            }
            else
                solve();
        }
        catch (Throwable uncaught)
        {
            Main.uncaught = uncaught;
        }
        finally
        {
            out.close();
        }
    }
    public static void main(String[] args) throws Throwable  {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        if (Main.uncaught != null) {
            throw Main.uncaught;
        }
    }
    static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out;
}
class FastScanner  {
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in)
    {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.util.Scanner;

public class A1350{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int test_cases = sc.nextInt();
		int n,k,res=0,min;

		while(test_cases > 0){

			n = sc.nextInt();
			//System.out.println("N is: " + n);
			k = sc.nextInt();
			//System.out.println("K is: " + k);

			for(int i = 1; i < k+1; i++){
				//System.out.println("I is:" + i);
				min = min_div(n);
				//System.out.println("Min is: " + min);
				res = min + n;
				//System.out.println("Res is: " + res);
				n = res;
				//System.out.println("N is: " + n);
			}

			System.out.println(res);

			test_cases--;
		}
	}

	static int min_div(int n){

			int i;

			for(i = 2; i <= n; i++){

				if(n % i == 0) break;
			}

			return i;
		}
}


import java.util.Scanner;
import java.lang.Math;

public class A1350{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int test_cases = sc.nextInt();
		int n,k,res=0,min;

		while(test_cases > 0){

			n = sc.nextInt();
			//System.out.println("N is: " + n);
			k = sc.nextInt();
			//System.out.println("K is: " + k);

			for(int i = 1; i < k+1; i++){
				//System.out.println("I is:" + i);
				min = min_div(n);
				if(min == 0) min = n;
				//System.out.println("Min is: " + min);
				res = min + n;
				//System.out.println("Res is: " + res);
				n = res;
				//System.out.println("N is: " + n);
			}

			System.out.println(res);

			test_cases--;
		}
	}

	static int min_div(int n){

			int res = 0;

			for(int i = 2; i <= Math.sqrt(n); i++){

				if(n % i == 0){

					res = i;
					break;
				}
			}

			return res;
		}
}


import java.util.Scanner;
import java.lang.Math;

public class A1350{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int test_cases = sc.nextInt();
		int n,k,res=0,min;

		while(test_cases > 0){

			n = sc.nextInt();
			//System.out.println("N is: " + n);
			k = sc.nextInt();
			//System.out.println("K is: " + k);

			for(int i = 1; i < k+1; i++){
				//System.out.println("I is:" + i);
				min = min_div(n);
				if(min == 0) min = n;
				//System.out.println("Min is: " + min);
				res = min + n;
				//System.out.println("Res is: " + res);
				n = res;
				//System.out.println("N is: " + n);
			}

			System.out.println(res);

			test_cases--;
		}
	}

	static int min_div(int n){

			int res = 0;
			int sqrt = Math.sqrt(n);

			for(int i = 2; i <= sqrt; i++){

				if(n % i == 0){

					res = i;
					break;
				}
			}

			return res;
		}
}


import java.util.Scanner;
import java.lang.Math;

public class A1350{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int test_cases = sc.nextInt();
		int n,k,res=0,min;

		while(test_cases > 0){

			n = sc.nextInt();
			//System.out.println("N is: " + n);
			k = sc.nextInt();
			//System.out.println("K is: " + k);
			//System.out.println("I is:" + i);
			min = min_div(n);
			//System.out.println("Min is: " + min);
			res = min + n + 2*(k-1);
			//System.out.println("Res is: " + res);
			n = res;
			//System.out.println("N is: " + n);

			System.out.println(res);

			test_cases--;
		}
	}

	static int min_div(int n){

			int sqrt = (int) Math.sqrt(n);
			int i;
			for(i = 2; i <= sqrt; i++){

				if(n % i == 0){
					break;
				}
			}

			if(i > sqrt) i = n;

			return i;
		}
}


import java.util.Scanner;
import java.lang.Math;

public class A1350{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int test_cases = sc.nextInt();
		int n,k,res=0,min;

		while(test_cases > 0){

			n = sc.nextInt();
			//System.out.println("N is: " + n);
			k = sc.nextInt();
			//System.out.println("K is: " + k);

			for(int i = 1; i < k+1; i++){
				//System.out.println("I is:" + i);
				min = min_div(n);
				if(min == 0) min = n;
				//System.out.println("Min is: " + min);
				res = min + n;
				//System.out.println("Res is: " + res);
				n = res;
				//System.out.println("N is: " + n);
			}

			System.out.println(res);

			test_cases--;
		}
	}

	static int min_div(int n){

			int res = 0;
			int sqrt = (int) Math.sqrt(n);

			for(int i = 2; i < 10; i++){

				if(n % i == 0){

					res = i;
					break;
				}
			}

			return res;
		}
}


import java.util.Scanner;
import java.lang.Math;

public class A1350{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int test_cases = sc.nextInt();
		int n,k,res=0,min;

		while(test_cases > 0){

			n = sc.nextInt();
			//System.out.println("N is: " + n);
			k = sc.nextInt();
			//System.out.println("K is: " + k);
			//System.out.println("I is:" + i);
			min = min_div(n);
			//System.out.println("Min is: " + min);
			res = min + n + 2*(k-1);
			//System.out.println("Res is: " + res);
			n = res;
			//System.out.println("N is: " + n);

			System.out.println(res);

			test_cases--;
		}
	}

	static int min_div(int n){

			int sqrt = (int) Math.sqrt(n);

			for(int i = 2; i <= sqrt; i++){

				if(n % i == 0){
					break;
				}
			}

			if(i > sqrt) i = n;

			return i;
		}
}


import java.util.Scanner;
import java.lang.Math;

public class A1350{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int test_cases = sc.nextInt();
		int n,k,res=0,min;

		while(test_cases > 0){

			n = sc.nextInt();
			//System.out.println("N is: " + n);
			k = sc.nextInt();
			//System.out.println("K is: " + k);

			for(int i = 1; i < k+1; i++){
				//System.out.println("I is:" + i);
				min = min_div(n);
				if(min == 0) min = n;
				//System.out.println("Min is: " + min);
				res = min + n;
				//System.out.println("Res is: " + res);
				n = res;
				//System.out.println("N is: " + n);
			}

			System.out.println(res);

			test_cases--;
		}
	}

	static int min_div(int n){

			int res = 0;
			int sqrt = (int) Math.sqrt(n);

			for(int i = 2; i <= sqrt; i++){

				if(n % i == 0){

					res = i;
					break;
				}
			}

			return res;
		}
}


/**
 * @author vivek
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {
    private static void solveTC(int __) {

        /* For Google */
//		ans.append("Case #").append(__).append(": ");

        //code start

        int n = scn.nextInt();
        int k = scn.nextInt();

        if (n%2!=0){
            k--;
            n+=(smallestFactor(n));
        }

        print(n+2*k);

        //code end

        ans.append("\n");
    }

    private static int smallestFactor(int n) {
        for (int i = 2; i <= Math.sqrt(n)+1; i++) {
            if (n%i==0){
                return i;
            }
        }

        return n;
    }

    private static int gcd(int i, int j) {
        return (j == 0) ? i : gcd(j, i % j);
    }

    static void print(Object obj) {
        ans.append(obj.toString());
    }

    public static void main(String[] args) {

        scn = new Scanner();
        ans = new StringBuilder();
        int t = scn.nextInt();
//		int t = 1;
        for (int i = 1; i <= t; i++) {
            solveTC(i);
        }
        System.out.print(ans);
    }

    static Scanner scn;
    static StringBuilder ans;

    //Fast Scanner
    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            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;
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        Integer[] nextIntegerArray(int n) {
            Integer[] array = new Integer[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLong();
            }
            return array;
        }

        String[] nextStringArray() {
            return nextLine().split(" ");
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
                array[i] = next();
            }
            return array;
        }
    }
}


/**
 * @author vivek
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {
    private static void solveTC(int __, HashMap<Integer, Integer> map) {

        /* For Google */
//		ans.append("Case #").append(__).append(": ");

        //code start

        int n = scn.nextInt();
        int k = scn.nextInt();

        for (int i = 0; i < k; i++) {
            n += map.get(n);
        }

        print(n);

        //code end

        ans.append("\n");
    }

    private static int gcd(int i, int j) {
        return (j == 0) ? i : gcd(j, i % j);
    }

    static void print(Object obj) {
        ans.append(obj.toString());
    }

    public static void main(String[] args) {

        HashMap<Integer, Integer> map = new HashMap<>();

        for (int i = 2; i <= 1000000; i++) {

            if (map.containsKey(i)) {
                continue;
            }

            for (int j = i; j <= 1000000; j += i) {
                if (!map.containsKey(j))
                map.put(j, i);
            }

        }

        scn = new Scanner();
        ans = new StringBuilder();
        int t = scn.nextInt();
//		int t = 1;
        for (int i = 1; i <= t; i++) {
            solveTC(i, map);
        }
        System.out.print(ans);
    }

    static Scanner scn;
    static StringBuilder ans;

    //Fast Scanner
    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            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;
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        Integer[] nextIntegerArray(int n) {
            Integer[] array = new Integer[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLong();
            }
            return array;
        }

        String[] nextStringArray() {
            return nextLine().split(" ");
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
                array[i] = next();
            }
            return array;
        }
    }
}


/**
 * @author vivek
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {
    private static void solveTC(int __) {

        /* For Google */
//		ans.append("Case #").append(__).append(": ");

        //code start

        int n = scn.nextInt();
        int k = scn.nextInt();

        for (int i = 0; i < k; i++) {
            n += map.get(n);
        }

        print(n);

        //code end

        ans.append("\n");
    }

    private static int gcd(int i, int j) {
        return (j == 0) ? i : gcd(j, i % j);
    }

    static void print(Object obj) {
        ans.append(obj.toString());
    }

    static HashMap<Integer, Integer> map;

    public static void main(String[] args) {

        map = new HashMap<>();

        for (int i = 2; i <= 1000000; i++) {

            if (map.containsKey(i)) {
                continue;
            }

            for (int j = i; j <= 1000000; j += i) {
                if (!map.containsKey(j))
                    map.put(j, i);
            }

        }

        scn = new Scanner();
        ans = new StringBuilder();
        int t = scn.nextInt();
//		int t = 1;
        for (int i = 1; i <= t; i++) {
            solveTC(i);
        }
        System.out.print(ans);
    }

    static Scanner scn;
    static StringBuilder ans;

    //Fast Scanner
    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            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;
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        Integer[] nextIntegerArray(int n) {
            Integer[] array = new Integer[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLong();
            }
            return array;
        }

        String[] nextStringArray() {
            return nextLine().split(" ");
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
                array[i] = next();
            }
            return array;
        }
    }
}


import java.util.*;
public class Orac
{
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		while(t-->0)
		{
		long n=scan.nextInt();
		int k=scan.nextInt();
		boolean f=true;

			for(int i=2;i<10&&i<n;i++)
			{
				if(n%i==0)
				{
					n=n+i;
					f=false;
					break;
				}else
				{
				f=true;
				}
			}
			if(f)
			{
				n=n+n;
			}
				n=n+2*(k-1);

		System.out.println(n);
		}
	}
}


import java.util.*;
public class Orac
{
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		while(t-->0)
		{
		int n=scan.nextInt();
		int k=scan.nextInt();
		boolean f=true;
		while(k-->0)
		{
			for(int i=2;i<10;i++)
			{
				if(n%i==0)
				{
					n=n+i;
					f=false;
					break;
				}else
				{
				f=true;
				}
			}
			if(f)
			{
				n=n+n;
			}

		}
		System.out.println(n);
		}
	}
}


import java.util.*;
public class Orac
{
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		while(t-->0)
		{
		int n=scan.nextInt();
		int k=scan.nextInt();
		boolean f=true;

			for(int i=2;i<10&&i<n;i++)
			{
				if(n%i==0)
				{
					n=n+i;
					f=false;
					break;
				}else
				{
				f=true;
				}
			}
			if(f)
			{
				n=n+n;
			}
				n=n+2*(k-1);

		System.out.println(n);
		}
	}
}


import java.util.*;
public class Orac
{
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		while(t-->0)
		{
		int n=scan.nextInt();
		int k=scan.nextInt();
		boolean f=true;

			for(int i=2;i<10&&i<n;i++)
			{
				if(n%i==0)
				{
					n=n+i;
					f=false;
					break;
				}else
				{
				f=true;
				}
			}
			if(f)
			{
				n=n+n;
			}
			if(k!=1)
			{
				n=n+2*(k-1);
			}

		System.out.println(n);
		}
	}
}


import java.util.*;
public class Orac
{
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		while(t-->0)
		{
		long n=scan.nextInt();
		long k=scan.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.*;
import java.lang.*;
import java.io.*;
import java.math.*;

public class file
 {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
	static INPUT sc = new INPUT(br);
	static int INF = Integer.MAX_VALUE,NEG_INF = Integer.MIN_VALUE,SEM_INF = INF / 2,count = 0,MOD = 1000000007,ops = 0;
    static long MAX_INF = Long.MAX_VALUE;
    static BigInteger B = new BigInteger("1");
    //static Scanner sc = new Scanner(System.in);

	public static void main (String[] args) throws Exception
	{
	    try{
	    	preComp();
            int t = sc.getInt(br.readLine());
            while(t-- > 0)
            {
                testCase();
            }
            out.flush();
        }catch(Exception e){
            System.out.println("Exception Occured!");
            e.printStackTrace();
        }
	}
    public static void testCase() throws Exception
    {
    	int n = sc.nextInt();int k = sc.nextInt();
    	if(n % 2 == 0)
    		n += (2 * k);
    	else{
    		n += getSmall(n);
    		n += (2 * (k - 1));
    	}
    	writeln(n);
    }
    public static int getSmall(int n)
    {
    	for(int x = 2;x < n + 1;x++)
    		if(n % x == 0)
    			return x;
    	return n;
    }
    public static void preComp()
    {

    }

    public static void writeln() throws Exception
    {
        out.write("\n");
    }
    public static void write(Object o) throws Exception
    {
        out.write(String.valueOf(o));
    }
    public static void writeln(Object o) throws Exception
    {
        out.write(String.valueOf(o) + "\n");
    }
	public static void println()
    {
        System.out.println();
    }
	public static void print(Object o)
    {
        System.out.print(String.valueOf(o));
    }
    public static void println(Object o)
    {
        System.out.println(String.valueOf(o));
    }

}

class INPUT
{
    BufferedReader br;
    StringTokenizer st;

    public INPUT(BufferedReader br)
    {
        this.br = br;
    }

    /*RAW INPUTS*/

    public String next() throws Exception
    {
        if(st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String trimLine() throws Exception
    {
        try{
            return br.readLine().trim();
        }catch (Exception e){
            System.out.println("Exception Occured: " + e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

    public String nextLine() throws Exception
    {
        try{
            return br.readLine();
        }catch (Exception e){
            System.out.println("Exception Occured: " + e.getMessage());
            e.printStackTrace();
            return null;
        }

    }

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

    public float nextFloat() throws Exception
    {
        return Float.parseFloat(next());
    }

    public int  [] getIntArray( String s)
    {
        String input[] = s.split(" ");
        int res[] = new int[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getInt(input[x]);

        return res;
    }
    public long  [] getLongArray( String s)
    {
        String input[] = s.split(" ");
        long res[] = new long[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getLong(input[x]);

        return res;
    }

    public double  [] getDoubleArray( String s)
    {
        String input[] = s.split(" ");
        double res[] = new double[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getDouble(input[x]);

        return res;
    }

    public int[][] getIntMatrix(String s,int r,int c)
    {
        int i = 0;int mat[][] = new int[r][c];
        String st[] = s.split(" ");
        for(int x = 0;x < r;x++)
            for(int y =0 ;y < c;y++)
                mat[x][y] = Integer.parseInt(st[i++]);
        return mat;

    }

    public long[][] getlongMatrix(String s,int r,int c)
    {
        int i = 0;long mat[][] = new long[r][c];
        String st[] = s.split(" ");
        for(int x = 0;x < r;x++)
            for(int y =0 ;y < c;y++)
                mat[x][y] = Long.parseLong(st[i++]);
        return mat;

    }

    public int getInt(String s)
    {
        return Integer.parseInt(s);
    }
    public long getLong(String s)
    {
        return Long.parseLong(s);
    }
    public float getFloat(String s)
    {
        return Float.parseFloat(s);
    }
    public double getDouble(String s)
    {
        return Double.parseDouble(s);
    }

}


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

public class file
 {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
	static INPUT sc = new INPUT(br);
	static int INF = Integer.MAX_VALUE,NEG_INF = Integer.MIN_VALUE,SEM_INF = INF / 2,count = 0,MOD = 1000000007,ops = 0;
    static long MAX_INF = Long.MAX_VALUE;
    static BigInteger B = new BigInteger("1");
    //static Scanner sc = new Scanner(System.in);
    static int sf[] = new int[1000010];

	public static void main (String[] args) throws Exception
	{
	    try{
	    	preComp();
            int t = sc.getInt(br.readLine());
            while(t-- > 0)
            {
                testCase();
            }
            out.flush();
        }catch(Exception e){
            System.out.println("Exception Occured!");
            e.printStackTrace();
        }
	}
    public static void testCase() throws Exception
    {
    	int n = sc.nextInt();int k = sc.nextInt();
    	while(k-- > 0){
    		n += func(n);
    		// writeln("N is " + n + " Func of n is "+ func(n));
    	}
    	writeln(n);
    }
    public static int func(int n)
    {
    	return sf[n];
    }
    public static int findLow(int n)
    {
    	if(n % 2 == 0)
    		return 2;
    	for(int x = 3;x < n + 1;x++)
    		if(n % x == 0)
    			return x;
    	return n;
    }
    public static void preComp()
    {
    	sf[0] = -1;sf[1] = 1;sf[2] = 2;sf[3] = 3;
    	for(int x = 4;x < 100010;x++)
    		sf[x] = findLow(x);
    }

    public static void writeln() throws Exception
    {
        out.write("\n");
    }
    public static void write(Object o) throws Exception
    {
        out.write(String.valueOf(o));
    }
    public static void writeln(Object o) throws Exception
    {
        out.write(String.valueOf(o) + "\n");
    }
	public static void println()
    {
        System.out.println();
    }
	public static void print(Object o)
    {
        System.out.print(String.valueOf(o));
    }
    public static void println(Object o)
    {
        System.out.println(String.valueOf(o));
    }

}

class INPUT
{
    BufferedReader br;
    StringTokenizer st;

    public INPUT(BufferedReader br)
    {
        this.br = br;
    }

    /*RAW INPUTS*/

    public String next() throws Exception
    {
        if(st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String trimLine() throws Exception
    {
        try{
            return br.readLine().trim();
        }catch (Exception e){
            System.out.println("Exception Occured: " + e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

    public String nextLine() throws Exception
    {
        try{
            return br.readLine();
        }catch (Exception e){
            System.out.println("Exception Occured: " + e.getMessage());
            e.printStackTrace();
            return null;
        }

    }

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

    public float nextFloat() throws Exception
    {
        return Float.parseFloat(next());
    }

    public int  [] getIntArray( String s)
    {
        String input[] = s.split(" ");
        int res[] = new int[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getInt(input[x]);

        return res;
    }
    public long  [] getLongArray( String s)
    {
        String input[] = s.split(" ");
        long res[] = new long[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getLong(input[x]);

        return res;
    }

    public double  [] getDoubleArray( String s)
    {
        String input[] = s.split(" ");
        double res[] = new double[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getDouble(input[x]);

        return res;
    }

    public int[][] getIntMatrix(String s,int r,int c)
    {
        int i = 0;int mat[][] = new int[r][c];
        String st[] = s.split(" ");
        for(int x = 0;x < r;x++)
            for(int y =0 ;y < c;y++)
                mat[x][y] = Integer.parseInt(st[i++]);
        return mat;

    }

    public long[][] getlongMatrix(String s,int r,int c)
    {
        int i = 0;long mat[][] = new long[r][c];
        String st[] = s.split(" ");
        for(int x = 0;x < r;x++)
            for(int y =0 ;y < c;y++)
                mat[x][y] = Long.parseLong(st[i++]);
        return mat;

    }

    public int getInt(String s)
    {
        return Integer.parseInt(s);
    }
    public long getLong(String s)
    {
        return Long.parseLong(s);
    }
    public float getFloat(String s)
    {
        return Float.parseFloat(s);
    }
    public double getDouble(String s)
    {
        return Double.parseDouble(s);
    }

}


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

public class file
 {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
	static INPUT sc = new INPUT(br);
	static int INF = Integer.MAX_VALUE,NEG_INF = Integer.MIN_VALUE,SEM_INF = INF / 2,count = 0,MOD = 1000000007,ops = 0;
    static long MAX_INF = Long.MAX_VALUE;
    static BigInteger B = new BigInteger("1");
    //static Scanner sc = new Scanner(System.in);

	public static void main (String[] args) throws Exception
	{
	    try{
            int t = sc.getInt(br.readLine());
            while(t-- > 0)
            {
                testCase();
            }
            out.flush();
        }catch(Exception e){
            System.out.println("Exception Occured!");
            e.printStackTrace();
        }
	}
    public static void testCase() throws Exception
    {
    	long n = sc.nextInt();int k = sc.nextInt();
    	while(k-- > 0){
    		n += func(n);
    		// writeln("N is " + n + " Func of n is "+ func(n));
    	}
    	writeln(n);
    }
    public static long func(long n)
    {
    	long add = findLow(n);
    	return add;
    }
    public static long findLow(long n)
    {
    	if(n % 2 == 0)
    		return 2;
    	for(long x = 3;x < n + 1;x++)
    		if(n % x == 0)
    			return x;
    	return n;
    }

    public static void writeln() throws Exception
    {
        out.write("\n");
    }
    public static void write(Object o) throws Exception
    {
        out.write(String.valueOf(o));
    }
    public static void writeln(Object o) throws Exception
    {
        out.write(String.valueOf(o) + "\n");
    }
	public static void println()
    {
        System.out.println();
    }
	public static void print(Object o)
    {
        System.out.print(String.valueOf(o));
    }
    public static void println(Object o)
    {
        System.out.println(String.valueOf(o));
    }

}

class INPUT
{
    BufferedReader br;
    StringTokenizer st;

    public INPUT(BufferedReader br)
    {
        this.br = br;
    }

    /*RAW INPUTS*/

    public String next() throws Exception
    {
        if(st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String trimLine() throws Exception
    {
        try{
            return br.readLine().trim();
        }catch (Exception e){
            System.out.println("Exception Occured: " + e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

    public String nextLine() throws Exception
    {
        try{
            return br.readLine();
        }catch (Exception e){
            System.out.println("Exception Occured: " + e.getMessage());
            e.printStackTrace();
            return null;
        }

    }

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

    public float nextFloat() throws Exception
    {
        return Float.parseFloat(next());
    }

    public int  [] getIntArray( String s)
    {
        String input[] = s.split(" ");
        int res[] = new int[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getInt(input[x]);

        return res;
    }
    public long  [] getLongArray( String s)
    {
        String input[] = s.split(" ");
        long res[] = new long[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getLong(input[x]);

        return res;
    }

    public double  [] getDoubleArray( String s)
    {
        String input[] = s.split(" ");
        double res[] = new double[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getDouble(input[x]);

        return res;
    }

    public int[][] getIntMatrix(String s,int r,int c)
    {
        int i = 0;int mat[][] = new int[r][c];
        String st[] = s.split(" ");
        for(int x = 0;x < r;x++)
            for(int y =0 ;y < c;y++)
                mat[x][y] = Integer.parseInt(st[i++]);
        return mat;

    }

    public long[][] getlongMatrix(String s,int r,int c)
    {
        int i = 0;long mat[][] = new long[r][c];
        String st[] = s.split(" ");
        for(int x = 0;x < r;x++)
            for(int y =0 ;y < c;y++)
                mat[x][y] = Long.parseLong(st[i++]);
        return mat;

    }

    public int getInt(String s)
    {
        return Integer.parseInt(s);
    }
    public long getLong(String s)
    {
        return Long.parseLong(s);
    }
    public float getFloat(String s)
    {
        return Float.parseFloat(s);
    }
    public double getDouble(String s)
    {
        return Double.parseDouble(s);
    }

}


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

public class file
 {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
	static INPUT sc = new INPUT(br);
	static int INF = Integer.MAX_VALUE,NEG_INF = Integer.MIN_VALUE,SEM_INF = INF / 2,count = 0,MOD = 1000000007,ops = 0;
    static long MAX_INF = Long.MAX_VALUE;
    static BigInteger B = new BigInteger("1");
    //static Scanner sc = new Scanner(System.in);
    static int sf[] = new int[1000010];

	public static void main (String[] args) throws Exception
	{
	    try{
	    	preComp();
            int t = sc.getInt(br.readLine());
            while(t-- > 0)
            {
                testCase();
            }
            out.flush();
        }catch(Exception e){
            System.out.println("Exception Occured!");
            e.printStackTrace();
        }
	}
    public static void testCase() throws Exception
    {
    	int n = sc.nextInt();int k = sc.nextInt();
    	while(k-- > 0){
    		n += func(n);
    		// writeln("N is " + n + " Func of n is "+ func(n));
    	}
    	writeln(n);
    }
    public static int func(int n)
    {
    	return sf[n];
    }
    public static int findLow(int n)
    {
    	if(n % 2 == 0)
    		return 2;
    	for(int x = 3;x < n + 1;x++)
    		if(n % x == 0)
    			return x;
    	return n;
    }
    public static void preComp()
    {
    	sf[0] = -1;sf[1] = 1;
    	for(int x = 2;x < 100010;x++){
    		if(sf[x] != 0)
    			continue;
    		sf[x] = x;
    		for(int i = 2 * x;i < 100010;i += x)
    			if(sf[i] == 0)
    				sf[i] = x;
    	}
    	// for(int x = 0;x < 25;x++)
    	// 	print(sf[x] + " ");
    	// println();
    }

    public static void writeln() throws Exception
    {
        out.write("\n");
    }
    public static void write(Object o) throws Exception
    {
        out.write(String.valueOf(o));
    }
    public static void writeln(Object o) throws Exception
    {
        out.write(String.valueOf(o) + "\n");
    }
	public static void println()
    {
        System.out.println();
    }
	public static void print(Object o)
    {
        System.out.print(String.valueOf(o));
    }
    public static void println(Object o)
    {
        System.out.println(String.valueOf(o));
    }

}

class INPUT
{
    BufferedReader br;
    StringTokenizer st;

    public INPUT(BufferedReader br)
    {
        this.br = br;
    }

    /*RAW INPUTS*/

    public String next() throws Exception
    {
        if(st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String trimLine() throws Exception
    {
        try{
            return br.readLine().trim();
        }catch (Exception e){
            System.out.println("Exception Occured: " + e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

    public String nextLine() throws Exception
    {
        try{
            return br.readLine();
        }catch (Exception e){
            System.out.println("Exception Occured: " + e.getMessage());
            e.printStackTrace();
            return null;
        }

    }

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

    public float nextFloat() throws Exception
    {
        return Float.parseFloat(next());
    }

    public int  [] getIntArray( String s)
    {
        String input[] = s.split(" ");
        int res[] = new int[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getInt(input[x]);

        return res;
    }
    public long  [] getLongArray( String s)
    {
        String input[] = s.split(" ");
        long res[] = new long[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getLong(input[x]);

        return res;
    }

    public double  [] getDoubleArray( String s)
    {
        String input[] = s.split(" ");
        double res[] = new double[input.length];
        for(int x = 0;x < res.length;x++)
            res[x] = getDouble(input[x]);

        return res;
    }

    public int[][] getIntMatrix(String s,int r,int c)
    {
        int i = 0;int mat[][] = new int[r][c];
        String st[] = s.split(" ");
        for(int x = 0;x < r;x++)
            for(int y =0 ;y < c;y++)
                mat[x][y] = Integer.parseInt(st[i++]);
        return mat;

    }

    public long[][] getlongMatrix(String s,int r,int c)
    {
        int i = 0;long mat[][] = new long[r][c];
        String st[] = s.split(" ");
        for(int x = 0;x < r;x++)
            for(int y =0 ;y < c;y++)
                mat[x][y] = Long.parseLong(st[i++]);
        return mat;

    }

    public int getInt(String s)
    {
        return Integer.parseInt(s);
    }
    public long getLong(String s)
    {
        return Long.parseLong(s);
    }
    public float getFloat(String s)
    {
        return Float.parseFloat(s);
    }
    public double getDouble(String s)
    {
        return Double.parseDouble(s);
    }

}


import java.util.*;
import java.util.Scanner;
// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Solution {
    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 s=new FastReader();
        int q=s.nextInt();
        while(q-->0)
        {
            int num=s.nextInt();

            int operations=s.nextInt();
             if(num%2==0)
             {
                 System.out.println(num+2*(operations));
             }
             else{
                 int fact=0;
                 for(fact=2;fact<=num;fact++)
                 {
                     if(num%fact==0) break;
                 }
                 System.out.println(num+fact+2*(operations-1));
             }

        }

    }

}


import java.util.*;
import java.util.Scanner;
// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Solution {
    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 boolean isPrime(int n)
    {
        // Corner cases
        if (n <= 1) return false;
        if (n <= 3) return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0) return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
            return false;

        return true;
    }

    public static void main(String[] args) {

       FastReader s=new FastReader();
        int q=s.nextInt();
        while(q-->0)
        {
            int num=s.nextInt();

            int operations=s.nextInt();
            if(isPrime(num))
            {
             int ans=2*num+2*(operations-1);
             System.out.println(ans);
            }
          else if(num%2==0)
           {
               System.out.println(num+2*operations);

           }
           else if(num%3==0)
           {
               System.out.println(num+3+2*(operations-1));
           }

        }

    }

}


import java.util.*;
import java.util.Scanner;
// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Solution {
    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 boolean isPrime(int n)
    {
        // Corner cases
        if (n <= 1) return false;
        if (n <= 3) return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0) return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
            return false;

        return true;
    }

    static int  printDivisors(int n)
    {
        // Note that this loop runs till square root
         if(n%2==0)return 2;
         if(n%3==0)return 3;
         if(isPrime(n))return n;
         return 0;
    }

    public static void main(String[] args) {

       FastReader s=new FastReader();
        int q=s.nextInt();
        while(q-->0)
        {
            int num=s.nextInt();

            int operations=s.nextInt();
           if(num%2==0)
           {
               System.out.println(num+2*operations);
               continue;
           }
          int lastdivisor=num;
            while(operations-->0)
            {
               int ans=printDivisors(num);
            //  Collections.sort(divisor);
             num=num+ans;
             lastdivisor=ans;

            }
            System.out.println(num);
        }

    }

}


import java.util.*;
import java.util.Scanner;
// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Solution {
    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 int  printDivisors(int n,int lastdivisor)
    {
        // Note that this loop runs till square root

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

    public static void main(String[] args) {

       FastReader s=new FastReader();
        int q=s.nextInt();
        while(q-->0)
        {
            int num=s.nextInt();

            int operations=s.nextInt();
            if(num%2==0){
                System.out.println(num+2*operations);
                continue;
            }
          int lastdivisor=num;
            while(operations-->0)
            {
               int ans=printDivisors(num,lastdivisor);
            //  Collections.sort(divisor);
             num=num+ans;
             lastdivisor=ans;

            }
            System.out.println(num);
        }

    }

}


import java.util.*;
import java.util.Scanner;
// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Solution {
    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 boolean isPrime(int n)
    {
        // Corner cases
        if (n <= 1) return false;
        if (n <= 3) return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0) return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
            return false;

        return true;
    }

    public static void main(String[] args) {

       FastReader s=new FastReader();
        int q=s.nextInt();
        while(q-->0)
        {
            int num=s.nextInt();

            int operations=s.nextInt();
            if(isPrime(num))
            {
             long ans=2*num+2*(operations-1);
             System.out.println(ans);
            }
          else if(num%2==0)
           {
               long ans=num+2*operations;
               System.out.println(ans);

           }
           else if(num%3==0)
           {
               long ans=num+3+2*(operations-1);
               System.out.println(ans);
           }
           else if(num%5==0)
           {
               long ans=num+5+2*(operations-1);
               System.out.println(ans);
           }

        }

    }

}


import java.util.*;
import java.util.Scanner;
// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Solution {
    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 boolean isPrime(int n)
    {
        // Corner cases
        if (n <= 1) return false;
        if (n <= 3) return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0) return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
            return false;

        return true;
    }

    public static void main(String[] args) {

       FastReader s=new FastReader();
        int q=s.nextInt();
        while(q-->0)
        {
            int num=s.nextInt();

            int operations=s.nextInt();
            if(isPrime(num))
            {
             int ans=2*num+2*(operations-1);
             System.out.println(ans);
            }
          else if(num%2==0)
           {
               System.out.println(num+2*operations);

           }
           else if(num%3==0)
           {
               System.out.println(num+3+2*(operations-1));
           }
           else if(num%5==0)
           {
               System.out.println(num+5+2*(operations-1));
           }

        }

    }

}


import java.util.*;
import java.util.Scanner;
// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Solution {
    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  ArrayList<Integer> printDivisors(int n)
    {
        // Note that this loop runs till square root
        ArrayList<Integer>  map=new ArrayList<>();
        for (int i=1; i<=Math.sqrt(n); i++)
        {
            if (n%i==0)
            {
                // If divisors are equal, print only one
                if (n/i == i)
                    map.add(i);

                else // Otherwise print both
                    {
                        map.add(i);
                        map.add(n/i);
                    }
            }
        }
        return map;
    }

    public static void main(String[] args) {

       FastReader s=new FastReader();
        int q=s.nextInt();
        while(q-->0)
        {
            int num=s.nextInt();

            int operations=s.nextInt();
            while(operations-->0)
            {
             ArrayList<Integer> divisor=printDivisors(num);
             Collections.sort(divisor);
             num=num+divisor.get(1);

            }
            System.out.println(num);
        }

    }

}