Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit d2ee11e

Browse files
authored
Add files via upload
1 parent d954920 commit d2ee11e

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

CCC/ccc97s2.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.ArrayList;
5+
6+
public class ccc97s2 {
7+
8+
public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
9+
10+
public static void main(String[] args) throws IOException {
11+
int n = Integer.parseInt(in.readLine());
12+
13+
int number;
14+
ArrayList<Integer> firstFactors;
15+
ArrayList<Integer> secondFactors;
16+
boolean isNasty;
17+
18+
for (int i = 0; i < n; i++) {
19+
number = Integer.parseInt(in.readLine());
20+
firstFactors = new ArrayList<Integer>();
21+
secondFactors = new ArrayList<Integer>();
22+
isNasty = false;
23+
24+
for (int j = 1; j <= Math.sqrt(number); j++) {
25+
if (number % j == 0) {
26+
firstFactors.add(j);
27+
secondFactors.add(number / j);
28+
}
29+
}
30+
31+
for (int j = 0; j < firstFactors.size() - 1; j++) {
32+
for (int k = j + 1; k < firstFactors.size(); k++) {
33+
if ((firstFactors.get(j) - secondFactors.get(j) == firstFactors.get(k) + secondFactors.get(k)) ||
34+
(firstFactors.get(j) + secondFactors.get(j) == firstFactors.get(k) - secondFactors.get(k)) ||
35+
(secondFactors.get(j) - firstFactors.get(j) == secondFactors.get(k) + firstFactors.get(k)) ||
36+
(secondFactors.get(j) + firstFactors.get(j) == secondFactors.get(k) - firstFactors.get(k))) {
37+
isNasty = true;
38+
break;
39+
}
40+
}
41+
42+
if (isNasty) {
43+
break;
44+
}
45+
}
46+
47+
if (isNasty) {
48+
System.out.println(number + " is nasty");
49+
} else {
50+
System.out.println(number + " is not nasty");
51+
}
52+
}
53+
}
54+
55+
public static String readLine() throws IOException {
56+
return in.readLine();
57+
}
58+
59+
public static int readInt() throws IOException {
60+
return Integer.parseInt(readLine());
61+
}
62+
63+
public static long readLong() throws IOException {
64+
return Long.parseLong(readLine());
65+
66+
}
67+
public static double readDouble() throws IOException {
68+
return Double.parseDouble(readLine());
69+
}
70+
71+
public static char readCharacter() throws IOException {
72+
return readLine().charAt(0);
73+
}
74+
75+
public static String[] readSpaceInput() throws IOException {
76+
return in.readLine().split(" ");
77+
}
78+
}

0 commit comments

Comments
 (0)