DIVSUM - Divisor Summation

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.

Input

An integer stating the number of test cases (equal to about 200000), and that many lines follow, each containing one integer between 1 and 500000 inclusive.

Output

One integer each line: the divisor summation of the integer given respectively.

Example

Sample Input:
3
2
10
20

Sample Output:
1
8
22

Warning: large Input/Output data, be careful with certain languages


Added by:Neal Zane
Date:2004-06-10
Time limit:3s
Source limit:5000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Neal Zane

hide comments
2013-04-15 15:57:39 titangate
takes 0.4s for 200000 cases on my computer but got TLE :/
2013-04-15 15:57:39 Pandian
This is totally unfair. . Got acc after including the test case for 0.But in the problem it was specified only 1 to 500000. Pls change it . . .
2013-04-15 15:57:39 sandeep
my algo is working in O(sqrt(n)).. But still i am getting TLE..
That's because sqrt(n)*T won't fit in time. you need optimization.

Last edit: 2012-02-03 13:28:53
2013-04-15 15:57:39 Ahmed Abdel Samad
for the test case of "1" shall it output one or zero?

Last edit: 2012-01-25 14:14:21
2013-04-15 15:57:39 Michael Yockey
It would seem that, since there are zero ruby solutions, that the time limit is much too short for the amount of IO required.
2013-04-15 15:57:39 Pavel
cin and cout are slow, use scanf and printf instead

Last edit: 2011-10-24 02:33:22
2013-04-15 15:57:39 avinash choudhary
for 1 its 0..mind it...:)
2013-04-15 15:57:39 Trimbitas Petru
I think the time limit is to low. The same algorithm using streams gets tle.
2013-04-15 15:57:39 Santiago Palacio
@Vasanth.N there are 2 options, 1 your program does not know when to halt and keeps looping, or 2 (most likely) the algorithm is not fast enough and should be changed, also there could be some I/O optimization needed, but in this problem it's unlikely.
2013-04-15 15:57:39 Vasanth.N
why time limit exceeded?????

Last edit: 2011-06-22 06:54:34
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.