Hello coders, today we are going to solve Andrew and the Meatballs again Codechef Solution|Problem Code:AMMEAT2.

Problem
Andrew likes meatballs very much as you know.
He has N plates of meatballs, here the ith plate contains exactly i meatballs. Andrew wants to take exactly K plates to his trip to Las Vegas.
On this occasion, he wants to choose the K plates by a strange way: if both ith and jth plates are chosen, then i and j must not be relative prime, for all 1 ≤ i < j ≤ N.
Please help him to choose K plates. Output one of the possible choices.
Input
The first line of the input contains an integer T, denoting the number of test cases. The description of T test cases follows. The first line and only line of each test case contains two space-separated integers N and K.
Output
For each test case, output K distinct integers, denoting the number of selected plates, where the plates are numbered from 1 to N. If there are multiple solutions, any one will do. If it is impossible to choose K plates, print only one integer -1.
Constraints
- 1 ≤ T ≤ 7
- 1 ≤ K ≤ N ≤ 777
Sample Input 1
2
100 3
100 100
Sample Output 1
45 63 35
-1
Andrew and the Meatballs again CodeChef Solution in JAVA
import java.util.Arrays; import java.util.Scanner; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int tc = 0; tc < T; tc++) { int N = sc.nextInt(); int K = sc.nextInt(); int[] solution = solve(N, K); if (solution == null) { System.out.println(-1); } else { System.out.println(String.join(" ", Arrays.stream(solution).mapToObj(String::valueOf).collect(Collectors.toList()))); } } sc.close(); } static int[] solve(int N, int K) { if (K == 1) { return new int[] { 1 }; } if (K > N / 2) { return null; } return IntStream.rangeClosed(1, K).map(x -> x * 2).toArray(); } }
Disclaimer: The above Problem (Andrew and the Meatballs again) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.