코테/프로그래머스

[프로그래머스/Lv. 0] 합성수 찾기

imname1am 2023. 2. 3. 10:17
반응형

내 코드

class Solution {
    public int solution(int n) {
        int answer = 0;
        
        for(int i=0 ; i<=n ; i++) {
            int cnt = 0;
            
            for(int j=1 ; j <= i ; j++) {              
                if(i % j == 0) {
                    cnt++;
                }
            }
            
            if(cnt >=3) answer++;
        }
        
        return answer;
    }
}

반응형