-
프로그래머스 - 약수의 합 [자바]Algorithms/- 프로그래머스 2022. 2. 2. 11:11
- 문제 링크 : 약수의 합
정답
class Solution { public int solution(int n) { int a = 0; for(int i=1; i<=n; i++){ if(n % i == 0){ a += i; } } return a; } }
분석
- 약수를 그냥 모두 더하면 된다.
반응형
class Solution {
public int solution(int n) {
int a = 0;
for(int i=1; i<=n; i++){
if(n % i == 0){
a += i;
}
}
return a;
}
}