코딩로그
[백준/BOJ/C++] 14782번 Bedtime Reading, I 본문
[문제]
Farmer John was performing his nightly bedtime reading duties for Bessie. "Oh, this gives me a headache," moaned Bessie. "But it's just simple number theory," replied FJ. "Let's go over it again. The sigma function of a number is just the sum of the divisors of the number. So, for a number like 12, the divisors are 1, 2, 3, 4, 6, and 12. Summing them we get 28." "That's all there is to it?" asked Bessie. "Yep." replied FJ. "Perhaps someone will write a program to calculate the sigma function of an integer I (1 <= I <= 1,000,000)."
[입력]
A single integer I.
[출력]
Output a line containing the sum of all of I's divisors.
[Source Code]
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int num, sum = 0;
cin >> num;
for(int i = 1; i <= num; i++){
if(num % i == 0)
sum += i;
}
cout << sum;
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
[백준/BOJ/C++] 13985번 Equality (0) | 2021.11.02 |
---|---|
[백준/BOJ/C++] 16018번 Occupy parking (0) | 2021.11.02 |
[백준/BOJ/C++] 11506번 占쏙옙 (0) | 2021.11.02 |
[백준/BOJ/C++] 10810번 공 넣기 (0) | 2021.11.02 |
[백준/BOJ/C++] 14581번 팬들에게 둘러싸인 홍준 (0) | 2021.11.01 |