목차
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
Problem Description
정수 n을 입력받아 n의 약수를 모두 더한 값을 리턴하는 함수, solution을 완성해주세요.
Example:
| n | return |
| 12 | 28 |
| 5 | 6 |
Constraints:
n은 0 이상 3000이하인 정수입니다.
My Solution (C#)
public static int Solution(int n)
{
int answer = 0;
for(int i = 1; i <= n; i++)
{
if (n % i == 0)
answer += i;
}
return answer;
}
'Problem solving > Algorithms' 카테고리의 다른 글
| [프로그래머스]최댓값과 최솟값 (C#) (0) | 2025.07.11 |
|---|---|
| [LeetCode] 733. Flood Fill (C#) (0) | 2025.07.09 |
| [LeetCode] 202. Happy Number(C#) (0) | 2024.01.19 |
| [LeetCode] 338. Counting Bits (C#) (0) | 2024.01.13 |
| [LeetCode] 125. Same Tree (C#) (0) | 2024.01.12 |