

For ‘N’ = 10
All factors are 1, 2, 5, 10.
So, the sum of them will be 18.
The first line contains a single integer ‘N’ denoting the size of the array.
The next line will contain 'N' space-separated integers denoting the elements of the array.
Print 'N' space-separated integers where the i'th element will denote the sum of all the factors of the i'th integer of the given array.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= N <= 10^2
1 <= X <= 10^5
Where 'N' represents the size of the given array and 'X' represents the elements of the array.
Time Limit: 1 sec.
We will iterate from 1 to ‘N’, and if the current number is a factor of ‘N’, we will add it to our answer.
Algorithm:
We can observe that the factors of any integer come in pairs. For each factor ‘D1’ such that 1 <= ‘D1’ <= sqrt(‘N’) , there will be another factor ‘D2’ = ‘N’ / ‘D1’ such that sqrt(‘N’) <= ‘D2’ <= ‘N’. But we have to be careful when ‘D1’ is equal to ‘D2’. In that case, we will consider ‘D1’ only once.
We will iterate from 1 to sqrt(‘N’). For each factor of ‘N’, we will also consider the other factor ‘N’ / ‘i’ and add them to the answer.
Algorithm:
Let ‘p1’,’p2’,....,’ pm’ be the prime factors of a number ‘N’, and let ‘a1’,’a2’,....,’am’ be the highest powers of the prime factors respectively, then the sum of all the factors can be written as:
‘SUM’ = ( 1 + p1 + p1^2 + …. + p1^a1) * ( 1 + p2 + p2^2 + …. + p2^a2) * …. * ( 1 + pm + pm^2 + …. + pm^am).
So now we will implement this to solve our problem.
We will use the Sieve of Eratosthenes to precompute the sum of all the divisors for each possible integer and store it in the ‘sum’ array. Then we can just take the required elements from the ‘sum’ array.
More details about the Sieve of Eratosthenes can be found at the given link:
https://cp-algorithms.com/algebra/sieve-of-eratosthenes.html