Sphere Online Judge

SPOJ Problem Set (classical)

74. Divisor Summation

Problem code: DIVSUM

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
Languages:All except: TECS
Resource:Neal Zane

hide comments
2010-08-21 11:01:34 yyf
thinking from another way
2010-08-19 17:20:01 Chandni
i am continuously getting NZEC. can't figure out y! help.
2010-08-07 13:05:38 Bharath Sivaram
Check if ur code works for perfect squares.........
2010-08-01 22:52:57 Taras Brzezinsky
use some preprocessing, e.g. find the smallest dividor for every numbers less or equal 500000
2010-07-10 19:18:30 prabhath
do sqrt work with this compiler
can any one tell output for 500000
iam getting 730453
i get wrong answer wen i submit
2010-06-20 08:01:05 Harits E.
A simple, mindless recursion isn't enough, i guess... TLE.

Last edit: 2010-06-20 08:04:30
2010-06-05 02:10:56 anon
I had the same experience as wilq in C++ (scanf / printf were 3x faster then cin / cout)
2010-05-28 11:38:04 SCQ
Why am I wrong? I got wrong answer and not TLE, which means my code ran on time. I tested against many test cases and got the correct answer. I took into account the special case of 1 as well. I also checked and made sure that there is no integer overflow (the biggest output is only 500k+). So why am I wrong? :(

Last edit: 2010-05-28 11:41:00
2010-02-26 13:58:36 Kumar Anurag
for n=1 output is 0.
Take care otherwise WA.
2009-11-18 08:49:52 nthrgeek
Not necessarily,I solved this problem using three different approaches,every time I used <iostream>.

Last edit: 2009-11-18 08:50:28
SPOJ System © 2010 Sphere Research Labs. All Rights Reserved.