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 Santiago Palacio
@ alg0: an O(sqrt(n)) algorithm should pass, mine did, look for I/O optimizations.

Last edit: 2011-06-13 06:07:00
2013-04-15 15:57:39 SD
Why TLE??? Although i m generating the array for sum only one time???
2013-04-15 15:57:39 Ocean Blue
do you have to use buffers to avoid TLE??
2013-04-15 15:57:39 alg0_seekar
hi guys i m using O(sqrt(n) algorithm still getting TLE..can any one suggest what optimization still i needed..??
2013-04-15 15:57:39 Piotr KÄ…kol
@Neeraj Bhat - Yup.
2013-04-15 15:57:39 Neeraj Bhat
is output for 500000 is 730453 ???
2013-04-15 15:57:39 bashrc is back
precomputation+some mathematics=AC
2013-04-15 15:57:39 Santiago Palacio
TLE? i dont believe it! i think i'm using a good algorithm, and efficient io.
2013-04-15 15:57:39 !!!!!
it depends how you factorize ur number..... other wise u'll get tle
2013-04-15 15:57:39 sri
why TLE??? i was using a nice loopings to calculate.. still tle????
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.