human
Can you provide a code to find two numbers made up of a given digit such that their difference is divisible by N and the other steps required given the following:
Find two numbers made up of a given digit such that their difference is divisible by N | Function to implement the above approach.
Hashmap to store remainder - length of the number as key - value pairs.
Iterate till N + 1 length.
Search remainder in the map.
If remainder is not already present insert the length for the corresponding remainder.
Keep increasing M.
To keep M in range of integer.
Length of one number is the current Length.
Length of the other number is the length paired with current remainder in map.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find two numbers made up of a given digit such that their difference is divisible by N and the other steps required.
 def findNumbers ( N , M ) :
	m = M
	remLen = { }
	for len1 in range ( 1 , N + 1 , 1 ) :
		remainder = M % N
		if ( remLen . get ( remainder ) == None ) :
			remLen [ remainder ] = len1
		else :
			break
		M = M * 10 + m
		M = M % N
	LenA = len1
	LenB = remLen [ remainder ]
	for i in range ( LenB ) :
		print ( m , end = " " )
	print ( " ▁ " , end = " " )
	for i in range ( LenA ) :
		print ( m , end = " " )
	return
if __name__ == ' _ _ main _ _ ' :
	N = 8
	M = 2
	findNumbers ( N , M )