human
Minimize sum of K positive integers with given LCM | Function to find the prime power of X.
Stores prime powers of X.
Iterate over the range [ 2 , sqrt ( X ) ].
If X is divisible by i.
Stores prime power.
Calculate prime power of X.
Update X.
Update p.
Insert prime powers into primePow [ ].
If X exceeds 1.
Function to calculate the sum of array elements.
Stores sum of array elements.
Traverse the array.
Update sum.
Function to partition array into K groups such that sum of elements of the K groups is minimum.
If count of prime powers is equal to pos.
Stores minimum sum of of each partition of arr [ ] into K groups.
Traverse the array arr [ ].
Include primePow [ pos ] into i - th groups.
Update res.
Remove factors [ pos ] from i - th groups.
Utility function to calculate minimum sum of K positive integers whose LCM is X.
Stores all prime powers of X.
Stores count of prime powers.
Stores minimum sum of K positive integers whose LCM is X.
If n is less than or equal to k.
Traverse primePow [ ] array.
Update sum.
Update sum.
arr [ i ] : Stores element in i - th group by partitioning the primePow [ ] array.
Update sum.
Driver Code"
How can the above be solved in Python?
 ... Write me a code to minimize sum of K positive integers with given LCM and the other steps required?
assistant
#Here is code to minimize sum of K positive integers with given LCM and the other steps required.
 def primePower ( X ) :
	primePow = [ ]
	for i in range ( 2 , X + 1 ) :
		if i * i > X + 1 :
			break
		if ( X % i == 0 ) :
			p = 1
			while ( X % i == 0 ) :
				X //= i
				p *= i
			primePow . append ( p )
	if ( X > 1 ) :
		primePow . append ( X )
	return primePow
def getSum ( ar ) :
	sum = 0
	for i in ar :
		sum += i
	return sum
def getMinSum ( pos , arr , primePow ) :
	if ( pos == len ( primePow ) ) :
		return getSum ( arr )
	res = 10 ** 9
	for i in range ( len ( arr ) ) :
		arr [ i ] *= primePow [ pos ]
		res = min ( res , getMinSum ( pos + 1 , arr , primePow ) )
		arr [ i ] //= primePow [ pos ]
	return res
def minimumSumWithGivenLCM ( k , x ) :
	primePow = primePower ( x )
	n = len ( primePow )
	sum = 0
	if ( n <= k ) :
		for i in primePow :
			sum += i
		sum += k - n
	else :
		arr = [ 1 ] * ( k )
		sum = getMinSum ( 0 , arr , primePow )
	return sum
if __name__ == ' _ _ main _ _ ' :
	k = 3
	x = 210
	print ( minimumSumWithGivenLCM ( k , x ) )