-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLopPair.java
More file actions
82 lines (71 loc) · 2.17 KB
/
Copy pathLopPair.java
File metadata and controls
82 lines (71 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.Scanner;
import java.io.*;
public class LopPair {
public static class Pair<K, V> {
private K first;
private V second;
public Pair(K first, V second) {
this.first = first;
this.second = second;
}
public K getFirst() {
return this.first;
}
public V getSecond() {
return this.second;
}
public void setFirst(K first) {
this.first = first;
}
public void setSecond(V second) {
this.second = second;
}
public boolean isPrime() {
if (first instanceof Integer && second instanceof Integer) {
int num1 = (Integer) first;
int num2 = (Integer) second;
return isPrimeNumber(num1) && isPrimeNumber(num2);
}
return false;
}
private boolean isPrimeNumber(int num) {
if (num <= 1) {
return false;
}
if (num <= 3) {
return true;
}
if (num % 2 == 0 || num % 3 == 0) {
return false;
}
for (int i = 5; i * i <= num; i += 6) {
if (num % i == 0 || num % (i + 2) == 0) {
return false;
}
}
return true;
}
@Override
public String toString() {
return this.first + " " + this.second;
}
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new File("DATA.in"));
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
boolean check = false;
for (int i = 2; i <= 2 * Math.sqrt(n); i++) {
Pair<Integer, Integer> p = new Pair<>(i, n - i);
if (p.isPrime()) {
System.out.println(p);
check = true;
break;
}
}
if (!check)
System.out.println(-1);
}
}
}