[ 프로그래머스 ] 약수의 합 (연습문제)
코드
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int solution(int n) {
int answer = 0;
vector<int> sumArr;
int checkNum;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i*j==n) {
sumArr.push_back(i);
sumArr.push_back(j);
break;
}
}
}
for(int i=0;i<sumArr.size()/2;i++){
answer+=sumArr[i];
}
return answer;
}