human
Sum of Factors of a Number using Prime Factorization | Using SieveOfEratosthenes to find smallest prime factor of all the numbers . For example , if N is 10 , s [ 2 ] = s [ 4 ] = s [ 6 ] = s [ 10 ] = 2 s [ 3 ] = s [ 9 ] = 3 s [ 5 ] = 5 s [ 7 ] = 7.
Create a boolean list " prime [ 0 . . n ] " and initialize all entries in it as false ..
Initializing smallest factor equal to 2 for all the even numbers.
For odd numbers less then equal to n.
s [ i ] for a prime is the number itself.
For all multiples of current prime number.
i is the smallest prime factor for number " i * j " ..
Function to find sum of all prime factors.
Declaring list to store smallest prime factor of i at i - th index.
Filling values in s [ ] using sieve function calling.
Current prime factor of N.
Power of current prime factor.
N is now Ns [ N ] . If new N also has smallest prime factor as currFactor , increment power.
Update current prime factor as s [ N ] and initializing power of factor as 1..
Driver Code"
Solution in Python:
assistant
#Here is code to sum of Factors of a Number using Prime Factorization and the other steps required.
 def sieveOfEratosthenes ( N , s ) :
	prime = [ False ] * ( N + 1 )
	for i in range ( 2 , N + 1 , 2 ) :
		s [ i ] = 2
	for i in range ( 3 , N + 1 , 2 ) :
		if prime [ i ] == False :
			s [ i ] = i
			for j in range ( i , ( N + 1 ) // i , 2 ) :
				if prime [ i * j ] == False :
					prime [ i * j ] = True
					s [ i * j ] = i
def findSum ( N ) :
	s = [ 0 ] * ( N + 1 )
	ans = 1
	sieveOfEratosthenes ( N , s )
	currFactor = s [ N ]
	power = 1
	while N > 1 :
		N //= s [ N ]
		if currFactor == s [ N ] :
			power += 1
			continue
		sum = 0
		for i in range ( power + 1 ) :
			sum += pow ( currFactor , i )
		ans *= sum
		currFactor = s [ N ]
		power = 1
	return ans
if __name__ == " _ _ main _ _ " :
	n = 12
	print ( " Sum ▁ of ▁ the ▁ factors ▁ is ▁ : " , end = " ▁ " )
	print ( findSum ( n ) )