Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Binary Tree
- Binary Search
- greedy
- string
- Data Structure
- Counting
- database
- Number Theory
- two pointers
- 코딩테스트
- java
- 코테
- 파이썬
- dynamic programming
- Tree
- Matrix
- Method
- Math
- Stack
- 자바
- array
- bit manipulation
- simulation
- 구현
- Class
- hash table
- SQL
- geometry
- sorting
- implement
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.1] 소수 찾기 본문
1. Input, Output, Example

- 1부터 입력받은 숫자 n 사이에 있는 소수의 개수를 반환
- 소수는 약수의 개수가 2개인 자연수를 뜻한다.
2. Constraint
1) n은 2이상 1,000,000이하의 자연수
3. Code
import java.util.*;
class Solution {
public int solution(int n) {
boolean[] prime = new boolean[n+1];
Arrays.fill(prime, true);
for(int i=2 ; i<=n ; i++)
if(prime[i])
for(int j=i*2 ; j<=n ; j+=i)
prime[j] = false;
int count = 0;
for(int i=2 ; i<=n ; i++)
if(prime[i]) count++;
return count;
}
}
- +1
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[프로그래머스/Lv.1] [1차] 다트 게임 (0) | 2023.07.04 |
---|---|
[프로그래머스/Lv.1] 실패율 (0) | 2023.07.04 |
[백준 온라인 저지] 1780. 종이의 개수 (0) | 2023.07.01 |
[백준 온라인 저지] 1992. 쿼드트리 (0) | 2023.07.01 |
[백준 온라인 저지] 1074. Z (0) | 2023.07.01 |