I don’t need to list all proper divisors, I just want to get its sum. Because for a small number, checking all proper divisors and adding them up is not a big deal. However, for a large number, this would run extremely slow. Any idea?
If the prime factorization of n is n=∏kpakk, where the pk are the distinct prime factors and the ak are the positive integer exponents, the sum of all the positive integer factors is ∏k(ak∑i=0pik).
For example, the sum of all of the factors of 120=23⋅3⋅5 is (1+2+22+23)(1+3)(1+5)=15⋅4⋅6=360.
For proper factors, subtract n from this sum. This may or may not be faster, depending on the number and how you’d get the prime factorization, but this is the typical technique for high school contest problems of this sort.