문제 설명
약수의 개수가 세 개 이상인 수를 합성수라고 합니다. 자연수 n이 매개변수로 주어질 때 n이하의 합성수의 개수를 return하도록 solution 함수를 완성해주세요.
입출력 예
나의 풀이
class Solution {
public int solution(int n) {
int answer = 0;
int num = 0;
for(int i = 4; i <= n; i++){
for(int j = 1; j <= i; j++){
if(i % j == 0){
num++;
}
}
if(num >= 3){
answer++;
}
num = 0;
}
return answer;
}
}
나의 풀이
function solution(n) {
let answer = 0;
let num = 0;
for(let i = 4; i <= n; i++){
for(let j = 1; j <= i; j++){
if(i % j == 0){
num++;
}
}
if(num >= 3){
answer++;
}
num = 0;
}
return answer;
}