human
Count pairs from a given range having even sum | Function to find the count of ordered pairs having even sum.
Stores count of even numbers in the range [ L , R ].
If L is even.
Update count_even.
Update count_odd.
Stores count of odd numbers in the range [ L , R ].
Update count_odd.
Update count_odd.
Stores count of pairs whose sum is even and both elements of the pairs are also even.
Stores count of pairs whose sum is even and both elements of the pairs are odd.
Print total ordered pairs whose sum is even.
Driver Code.
Given L & R.
Function Call"
Solution in Python:
assistant
#Here is code to count pairs from a given range having even sum and the other steps required.
 def countPairs ( L , R ) :
	count_even = 0
	if ( L % 2 == 0 ) :
		count_even = ( ( R // 2 ) - ( L // 2 ) + 1 )
	else :
		count_even = ( ( R // 2 ) - ( L // 2 ) )
	count_odd = 0
	if ( L % 2 == 0 ) :
		count_odd = ( ( ( R + 1 ) // 2 ) - ( ( L + 1 ) // 2 ) )
	else :
		count_odd = ( ( ( R + 1 ) // 2 ) - ( ( L + 1 ) // 2 ) + 1 )
	count_even *= count_even
	count_odd *= count_odd
	print ( count_even + count_odd )
if __name__ == ' _ _ main _ _ ' :
	L , R = 1 , 3
	countPairs ( L , R )