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


hide comments
Santiago Palacio: 2013-04-15 15:57:39

@ alg0: an O(sqrt(n)) algorithm should pass, mine did, look for I/O optimizations.

Last edit: 2011-06-13 06:07:00
SD: 2013-04-15 15:57:39

Why TLE??? Although i m generating the array for sum only one time???

Ocean Blue: 2013-04-15 15:57:39

do you have to use buffers to avoid TLE??

alg0_seekar: 2013-04-15 15:57:39

hi guys i m using O(sqrt(n) algorithm still getting TLE..can any one suggest what optimization still i needed..??

Piotr KÄ…kol: 2013-04-15 15:57:39

@Neeraj Bhat - Yup.

Neeraj Bhat: 2013-04-15 15:57:39

is output for 500000 is 730453 ???

bashrc is back: 2013-04-15 15:57:39

precomputation+some mathematics=AC

Santiago Palacio: 2013-04-15 15:57:39

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

sri: 2013-04-15 15:57:39

why TLE??? i was using a nice loopings to calculate.. still tle????


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