human
What is a code to sum of first K numbers which are not divisible by N and the other steps required given the following:
Sum of first K numbers which are not divisible by N | Function to find the sum.
Find the last multiple of N.
Find the K - th non - multiple of N.
Calculate the sum of all elements from 1 to val.
Calculate the sum of all multiples of N between 1 to val.
Driver code"
Solution in Python:
assistant
#Here is code to sum of first K numbers which are not divisible by N and the other steps required.
 def findSum ( n , k ) :
	val = ( k // ( n - 1 ) ) * n ;
	rem = k % ( n - 1 ) ;
	if ( rem == 0 ) :
		val = val - 1 ;
	else :
		val = val + rem ;
	sum = ( val * ( val + 1 ) ) // 2 ;
	x = k // ( n - 1 ) ;
	sum_of_multiples = ( x * ( x + 1 ) * n ) // 2 ;
	sum -= sum_of_multiples ;
	return sum ;
n = 7 ; k = 13 ;
print ( findSum ( n , k ) )