human
Sum of elements in given range from Array formed by infinitely concatenating given array | Function to find the sum of elements in a given range of an infinite array.
Stores the prefix sum.
Calculate the prefix sum.
Stores the sum of elements from 1 to L - 1.
Stores the sum of elements from 1 to R.
Print the resultant sum.
Driver Code"
Solution in Python:
 ... Can you provide a code to sum of elements in given range from Array formed by infinitely concatenating given array and the other steps required?
assistant
#Here is code to sum of elements in given range from Array formed by infinitely concatenating given array and the other steps required.
 def rangeSum ( arr , N , L , R ) :
	prefix = [ 0 for i in range ( N + 1 ) ]
	prefix [ 0 ] = 0
	for i in range ( 1 , N + 1 , 1 ) :
		prefix [ i ] = prefix [ i - 1 ] + arr [ i - 1 ]
	leftsum = ( ( L - 1 ) // N ) * prefix [ N ] + prefix [ ( L - 1 ) % N ]
	rightsum = ( R // N ) * prefix [ N ] + prefix [ R % N ]
	print ( rightsum - leftsum )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 5 , 2 , 6 , 9 ]
	L = 10
	R = 13
	N = len ( arr )
	rangeSum ( arr , N , L , R )