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 [Retired]
for 1 sum is 0.
2013-04-15 15:57:39 Eric Budiman Gosno
what happen with this problem??
first i submit and got AC
but after 1 hour, i submit the same source code and it got TLE
are the test case random or what? :0

Last edit: 2010-11-02 16:27:58
2013-04-15 15:57:39 !!!!!
any thing abt i need to take care specilly coz getting rite answers in my system(Just according to formula) still getting wrong ans here...
2013-04-15 15:57:39 Kousthub Raja
The sum of divisors of 1 is 0. Please be sure at this point. I got tied by this. He he ;)
2013-04-15 15:57:39 ~neo~
for 1 sum is 0 or 1.???
2014-01-22 09:25:41 Bhargav Krishna
i am using a sieve to store all values. so all i have to do is take the query and output the value. for n queries this takes O(n). But i am getting TLE. could anyone point out on how to make input and outputs faster.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.