Pages

Sunday, 15 February 2015

SPOJ PROBLEM 74. DIVISOR SUMMATION

Problem Link: http://www.spoj.com/problems/DIVSUM/

SUMMARY:
Given a natural number n (1 <= n <= 500000), please output the summation of all its proper divisors.
Definition: A proper divisor of a natural number is the divisor that is strictly less than the number.
e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and the divisor summation is: 1 + 2 + 4 + 5 + 10 = 22.

Logic
The logic for solving this question is that divisors always exist in pairs. So, for a number ‘t’, if ‘i’ is a divisor then ‘t/i’ is also a divisor.
And the smaller number of any divisor pair is always less than or equal to the square root of the number.


To View My Solution:
https://github.com/shivam04/spoj/blob/master/DIVSUM.cpp

No comments:

Post a Comment