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
- geometry
- 자바
- Binary Search
- Tree
- two pointers
- database
- array
- Math
- string
- Binary Tree
- dynamic programming
- SQL
- greedy
- hash table
- 코딩테스트
- java
- sorting
- Method
- Data Structure
- 코테
- 파이썬
- Matrix
- 구현
- Class
- implement
- Counting
- Number Theory
- bit manipulation
- simulation
- Stack
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 |