약수의 합을 구하면 됨.
#include <string>
#include <vector>
using namespace std;
int solution(int n) {
int answer = 0;
for (int i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
answer += i;
if (i != n / i)
answer += n / i;
}
}
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV1 자릿수 더하기 (0) | 2022.04.27 |
|---|---|
| [프로그래머스] (C++) LV1 이상한 문자 만들기 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 시저 암호 (0) | 2022.04.26 |
| [프로그래머스] (C++) LV1 문자열을 정수로 바꾸기 (0) | 2022.04.26 |
| [프로그래머스] (C++) LV1 수박수박수박수박수박수? (0) | 2022.04.26 |