java

[프로그래머스 - 자바] 약수의 합

tues 2023. 9. 7. 17:35

문제 설명

 

솔루션

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