728x90
SMALL

using System;

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

 

/////

 

using System;

public class Solution {
    public int solution(int n) {
        int answer = 0;
        
        if(n<4)
            return 0;
        
        for(int i= 4;i<=n;i++)
        {
            for(int j = 2;j<i;j++)
            {
                if(i%j==0)
                {
                    answer++;
                    break;
                }

            }
        }
        return answer;
    }
}

 

// 1과 자신이 아닌 경우의 약수 하나만 있으면 되니까 이렇게 짜도 된다.

 

파이썬

////

def solution(n):
    output = 0
    for i in range(4, n + 1):
        for j in range(2, int(i ** 0.5) + 1):
            if i % j == 0:
                output += 1
                break
    return output

/////

 

def get_divisors(n):
    return list(filter(lambda v: n % v ==0, range(1, n+1)))

def solution(n):
    return len(list(filter(lambda v: len(get_divisors(v)) >= 3, range(1, n+1))))

 

자바

/////

 

import java.util.stream.IntStream;

class Solution {
    public int solution(int n) {
        return (int) IntStream.rangeClosed(1, n).filter(i -> (int) IntStream.rangeClosed(1, i).filter(i2 -> i % i2 == 0).count() > 2).count();
    }
}

 

//////

 

class Solution {
    public int solution(int n) {
        int answer = 0;

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

        return answer;
    }
}

 

728x90

설정

트랙백

댓글