class Solution {
public int solution(int n) {
int answer = 0;
for(int i = 2; i <= n; i++){
int j = 2;
int cnt = 0;
while(j <= (int)Math.sqrt(i)){
if(i % j == 0){
cnt++;
break;
}
j++;
}
if(cnt == 0){
answer += 1;
}
}
return answer;
}
}
💬 문제개편으로 예시가 많이 없다. 여러번 반복해서 풀어보기
✔ 풀 때마다 해매는 문제이므로 꼭 다시 풀어보자..!
✔ Math.sqrt(i): 제곱근 구하기