https://school.programmers.co.kr/learn/courses/30/lessons/12921
1. ๋ฌธ์
n๊น์ง์ ์ ์ค ์์ ๊ฐ์๋ฅผ ๋ฐํํ๋ค.
2. ํ์ด
์์์ฐพ๊ธฐ๋ ์ด์ ์ข ์ธ์ฐ์
3. ์ฝ๋
class Solution {
public int solution(int n) {
int answer = 0;
for (int i=2; i<= n; i++) {
boolean flag = true;
for (int j=2; j<= Math.sqrt(i); j++) {
if (i % j == 0) {
flag = false;
break;
}
}
if (flag) {
answer++;
}
}
return answer;
}
}
4. ์ฌ๋ด
์์์ฐพ๊ธฐ.. ์ธ์๋ผ..
'Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] ํผ๋ก๋ - Java (0) | 2023.09.20 |
---|---|
[Programmers] ์์์ฐพ๊ธฐ (level 2) - Java (1) | 2023.09.18 |
[Programmers] ๋ชจ์๊ณ ์ฌ - Java (0) | 2023.09.16 |
[Programmers] ๋ฑ๊ตฃ๊ธธ - Java (0) | 2023.08.24 |
[Programmers] ์ผ๊ทผ ์ง์ - Java (0) | 2023.08.22 |