human
Rearrangement of a number which is also divisible by it | Perform hashing for given n.
perform hashing.
check whether any arrangement exists.
Create a hash for given number n The hash is of size 10 and stores count of each digit in n ..
check for all possible multipliers.
check hash table for both ..
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to rearrangement of a number which is also divisible by it and the other steps required.
 def storeDigitCounts ( n , Hash ) :
	while n > 0 :
		Hash [ n % 10 ] += 1
		n //= 10
def rearrange ( n ) :
	hash_n = [ 0 ] * 10
	storeDigitCounts ( n , hash_n )
	for mult in range ( 2 , 10 ) :
		curr = n * mult
		hash_curr = [ 0 ] * 10
		storeDigitCounts ( curr , hash_curr )
		if hash_n == hash_curr :
			return curr
	return - 1
if __name__ == " _ _ main _ _ " :
	n = 10035
	print ( rearrange ( n ) )