Files
Story-With-Thanh/J02025 - DÃY CON CÓ TỔNG NGUYÊN TỐ.java
T
2022-12-15 23:51:04 +07:00

48 lines
1.3 KiB
Java

import java.util.*;
import java.io.*;
public class Main {
static boolean primr(int x) {
if (x < 2)
return false;
if (x == 2)
return true;
if (x % 2 == 0)
return false;
for (int i = 3; i <= (int) Math.sqrt(x); i += 2) {
if (x % i == 0)
return false;
}
return true;
}
static void Try(int end, int[] a, int sum, String s) {
if (primr(sum)) System.out.println(s);
for (int i = a.length - 1; i > end; i--) {
Try(i, a, sum + a[i], s + a[i] + ' ');
}
}
public static void main(String[] args) throws IOException, ClassNotFoundException {
// Scanner sc = new Scanner(new File("ONLINE.in"));
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = sc.nextInt();
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] < a[j]) {
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
}
Try(-1, a, 0, "");
}
}
}