human
What is a code to count of distinct numbers formed by shuffling the digits of a large number N and the other steps required given the following:
Count of distinct numbers formed by shuffling the digits of a large number N | Recursive function to return the value of ( x ^ n ) % m.
Base Case.
If N is even.
Else N is odd.
Function to find modular inverse of a number x under modulo m.
Using Fermat 's little theorem.
Function to count of numbers formed by shuffling the digits of a large number N.
Modulo value.
Array to store the factorials upto the maximum value of N.
Store factorial of i at index i.
To store count of occurrence of a digit.
Increment the count of digit occured.
Assign the factorial of length of input.
Multiplying result with the modulo multiplicative inverse of factorial of count of i.
Print the result.
Given number as string.
Function call"
Solution in Python:
assistant
#Here is code to count of distinct numbers formed by shuffling the digits of a large number N and the other steps required.
 def modexp ( x , n , m ) :
	if ( n == 0 ) :
		return 1
	else :
		if ( n % 2 == 0 ) :
			return modexp ( ( x * x ) % m , n / 2 , m ) ;
		else :
			return ( x * modexp ( ( x * x ) % m , ( n - 1 ) / 2 , m ) % m )
def modInverse ( x , m ) :
	return modexp ( x , m - 2 , m )
def countNumbers ( N ) :
	m = 1000000007
	factorial = [ 0 for x in range ( 100001 ) ]
	factorial [ 0 ] = 1 ;
	for i in range ( 1 , 100001 ) :
		factorial [ i ] = ( factorial [ i - 1 ] * i ) % m
	count = [ 0 for x in range ( 10 ) ]
	for i in range ( 0 , 10 ) :
		count [ i ] = 0
	length = len ( N )
	for i in range ( 0 , length ) :
		count [ int ( N [ i ] ) ] += 1
	result = factorial [ int ( length ) ]
	for i in range ( 0 , 10 ) :
		result = ( result * modInverse ( factorial [ int ( count [ i ] ) ] , m ) ) % m
	print ( result )
N = "0223" ;
countNumbers ( N )