-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecimal.java
More file actions
48 lines (40 loc) · 1.14 KB
/
Decimal.java
File metadata and controls
48 lines (40 loc) · 1.14 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
package array;
import java.util.Scanner;
public class Decimal {
public static int solution2(int len) {
// 특정 숫자가 소수인지 확인하고
// 만일 소수라면 해당 소수의 배수를 소수가 아닌걸로 체크
int result = 0;
int[] intArray = new int[len + 1];
for (int i = 2; i < len; i++) {
if (intArray[i] == 0) {
result++;
for (int j = i; j < len; j+=i) {
intArray[j] = 1;
}
}
}
return result;
}
public static int solution1(int len) {
int result = 0;
for (int i = 2; i < len; i++) {
boolean isPrime = true;
for (int x = 2; x <= Math.sqrt(i); x++) {
if (i % x == 0) {
isPrime = false;
break;
}
}
if(isPrime){
result++;
}
}
return result;
}
public void main() {
Scanner in=new Scanner(System.in);
int len = in.nextInt();
System.out.println(solution2(len));
}
}