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
2015-03-07 14:54:20 Zoli
I got TLE for optimal solution in Python 3.4, any suggestions?

(Francky) => There's several PY3.4 AC, so your solution isn't optimal.

Last edit: 2015-03-07 15:15:52
2015-03-01 13:36:41 Otaku Jome
I have spent so much time optimising, but it still says it's too slow. There seems to be no fast enough solution.
2015-02-22 22:25:53 Abhinandan Agarwal
Small puny mistakes willl take me down someday ...
2015-02-21 15:03:21 Mahesh Kohli
should the answer be 0 for n=1?
2015-02-17 16:14:46 sarvagya
time limit exceeded :(
2015-02-11 07:44:32 Himanshu
make your own power function. the pow function in maths library rounds down when converting to integer. eg pow(5,2) will be returned as 24.
2015-01-18 12:58:49 Phạm Bãng Bãng
n <= 100000 and AC :D

--Francky--> (Shocked) It's true and we have too n<33333 !!!

Last edit: 2015-01-18 13:32:40
2014-11-27 02:01:41 Minsuk Kim
Python 2.7 novice here - keep on getting time limit exceeded although my code works perfectly fine. I have tried many test cases...
--ans(Francky)--> It's not easy with Python, you can see there's few AC with Python. With cube cluster, now, it's easier than with Pyramid as the time limit is more relax.

Last edit: 2014-11-27 02:18:55
2014-10-24 06:28:21 Vikas
Solved in just 0.24s. Nice Problem .
2014-10-08 14:08:14 mehmetin
Can the time limit be reduced for problems that have been changed to cube cluster? For this problem, it could be 1s or 0.5 s.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.