-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGoodDayBadDay.java
More file actions
98 lines (88 loc) · 2.56 KB
/
GoodDayBadDay.java
File metadata and controls
98 lines (88 loc) · 2.56 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
class TestClass {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int N = Integer.parseInt(line);
ArrayList<String> arint = new ArrayList<String>();
for (int i = 0; i < N; i++) {
arint.add(br.readLine());
}
for(int i = 0; i < N; i++){
System.out.println(goodBadCount(arint.get(i)));
}
}
public static String goodBadCount(String str) {
int badCount = 0, goodCount = 0;
boolean bad = false,first=true;
String[] splitStr = str.split("\\s+");
int h = Integer.parseInt(splitStr[0]);
ArrayList<Integer> ariniPrime = allPrimeNumber(h);
//System.out.println(ariniPrime);
int m = Integer.parseInt(splitStr[1]);
int s = Integer.parseInt(splitStr[2]);
int count = ariniPrime.size();
for (int k = h; k < 24; k++) {
System.out.println("h"+k);
if(first){
for (int j = m; j < 60; j++) {
System.out.println("m"+j);
for (int l = s; l < 60; l++) {
System.out.println("s"+l);
for(int c = count-1;c>=0;c--){
if (k%ariniPrime.get(c)==0 && j%ariniPrime.get(c)==0 && l%ariniPrime.get(c)==0) {
badCount = badCount + 1;
bad = true;
//System.out.println("bc"+badCount);
}
}
if(!bad){
goodCount = goodCount + 1;
//System.out.println("gc"+goodCount);
}
}
}
first=false;
}
else{
for (int j = 1; j < 60; j++) {
System.out.println("m"+j);
for (int l = 1; l < 60; l++) {
System.out.println("s"+l);
for(int c = count-1;c>=0;c--){
if (k%ariniPrime.get(c)==0 && j%ariniPrime.get(c)==0 && l%ariniPrime.get(c)==0) {
badCount = badCount + 1;
bad = true;
//System.out.println("bc"+badCount);
}
}
if(!bad){
goodCount = goodCount + 1;
//System.out.println("gc"+goodCount);
}
}
}
}
}
return badCount + ":" + goodCount;
}
public static ArrayList<Integer> allPrimeNumber(int number) {
ArrayList<Integer> arint = new ArrayList<Integer>();
for (int i = 2; i <= number; i++) {
if (isPrimeNumber(i)) {
arint.add(i);
}
}
return arint;
}
public static boolean isPrimeNumber(int number){
for(int i=2; i<=number/2; i++){
if(number % i == 0){
return false;
}
}
return true;
}
}