human
Count numbers from given range having odd digits at odd places and even digits at even places | Function to calculate 5 ^ p.
Stores the result.
Multiply 5 p times.
Return the result.
Function to count anumbers upto N having odd digits at odd places and even digits at even places.
Stores the count.
Stores the digits of N.
Insert the digits of N.
Reverse the vector to arrange the digits from first to last.
Stores count of digits of n.
Stores the count of numbers with i digits.
If the last digit is reached , subtract numbers eceeding range.
Iterate over athe places.
Stores the digit in the pth place.
Stores the count of numbers having a digit greater than x in the p - th position.
Calculate the count of numbers exceeding the range if p is even.
Calculate the count of numbers exceeding the range if p is odd.
Subtract the count of numbers exceeding the range from total count.
If the parity of p and the parity of x are not same.
Add count of numbers having i digits and satisfies the given conditions.
Return the total count of numbers tin.
Function to calculate the count of numbers from given range having odd digits places and even digits at even places.
Count of numbers in range [ L , R ] = Count of numbers tiR -.
Count of numbers ti ( L - 1 ).
Driver Code"
Solution in Python:
assistant
#Here is code to count numbers from given range having odd digits at odd places and even digits at even places and the other steps required.
 def getPower ( p ) :
	res = 1
	while ( p ) :
		res *= 5
		p -= 1
	return res
def countNumbersUtil ( N ) :
	count = 0
	digits = [ ]
	while ( N ) :
		digits . append ( N % 10 )
		N //= 10
	digits . reverse ( )
	D = len ( digits )
	for i in range ( 1 , D + 1 , 1 ) :
		res = getPower ( i )
		if ( i == D ) :
			for p in range ( 1 , D + 1 , 1 ) :
				x = digits [ p - 1 ]
				tmp = 0
				if ( p % 2 == 0 ) :
					tmp = ( ( 5 - ( x // 2 + 1 ) ) * getPower ( D - p ) )
				else :
					tmp = ( ( 5 - ( x + 1 ) // 2 ) * getPower ( D - p ) )
				res -= tmp
				if ( p % 2 != x % 2 ) :
					break
		count += res
	return count
def countNumbers ( L , R ) :
	print ( countNumbersUtil ( R ) - countNumbersUtil ( L - 1 ) )
L = 128
R = 162
countNumbers ( L , R )