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
2014-08-01 03:24:09 ashour
it gives me TLE
this my code : <snip>
could someone tell me why ?

Last edit: 2023-03-08 17:56:13
2014-07-11 17:22:37 [Lakshman]
@Mehmet Inal I think there is already another tutorial version with 10^6 test cases and tight time limit. http://www.spoj.com/problems/CHKL/
and we have DIVSUM2 in classical as well.
2014-07-11 16:42:01 mehmetin
Would it be possible that another version of this problem be put in classical section with tighter time limit and more test cases maybe? Or if there is such a version, which one is it?
2014-06-16 05:39:17 Aakash Gupta
for 1 its 0 :)
2014-05-29 14:18:35 Sumit Mishra
what answer expected if input is 1 ?
2014-05-21 10:25:49 Mayur Aggarwal
How can I verify why my soultion is giving wrong answer, anymethod to get test case for which wrong answer coming
--ans(Francky)--> It is easy to build a brute-force solution (slower but correct) and compare with home made random cases (+ all small cases). It's a method to be used with most of problems. Good luck.

Last edit: 2014-05-21 10:53:32
2014-05-21 10:03:03 Mayur Aggarwal
My code is also giving wrong answer, can anybody tell me the expected outputs for numbers 1 and the numbers which divisible by themself only ?
Any help would be appriciated
2014-05-19 20:38:05 p@dfoot
Do we have to specify the number of inputs?
2014-05-05 22:22:44 Kaushik
Nice question..!
Used O(sqrt(N)) TLE
Used Sieve, resolved TLE... but WA :P
Now AC. :)
2014-04-11 16:32:10 anon
i was happy doing this in first attempt but later on realized it was a tutorial question :(
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.