문제

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.

예제 입력 1

12

예제 출력 1

28

더보기

Solution

#include<stdio.h>

int main(void)
{
	int I, sum=0;

	scanf("%d", &I);

	for(int i=1;i<=I/2;i++)
		if(I%i==0)
			sum+=i;
	sum+=I;

	printf("%d\n", sum);
	return 0;
}
728x90

+ Recent posts