Print first N Mosaic numbers | Function to return the nth mosaic number ; Iterate from 2 to the number ; If i is the factor of n ; Find the count where i ^ count is a factor of n ; Divide the number by i ; Increase the count ; Multiply the answer with count and i ; Return the answer ; Function to print first N Mosaic numbers ; Driver code
def mosaic ( n ) : NEW_LINE INDENT ans = 1 NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT if ( n % i == 0 and n > 0 ) : NEW_LINE INDENT count = 0 ; NEW_LINE while ( n % i == 0 ) : NEW_LINE INDENT n = n // i NEW_LINE count += 1 ; NEW_LINE DEDENT ans *= count * i ; NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT def nMosaicNumbers ( n ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT print mosaic ( i ) , NEW_LINE DEDENT DEDENT n = 10 ; NEW_LINE nMosaicNumbers ( n ) ; NEW_LINE