Skip to content

Latest commit

 

History

History
22 lines (19 loc) · 486 Bytes

File metadata and controls

22 lines (19 loc) · 486 Bytes

프로그래머스 Level1 : 연습문제 약수의 합

class Solution {
    public int solution(int n) {
        int answer = 0;
        for(int i=1; i<=Math.sqrt(n); i++){
            if(n%i == 0){
                answer += i;
                answer += n/i;
            }
            
            if(i==Math.sqrt(n)){
                answer-= i;
            }
        }
        return answer;
    }
}