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
function mosaic ( n ) { var i , ans = 1 ; for ( i = 2 ; i <= n ; i ++ ) { if ( n % i == 0 && n > 0 ) { var count = 0 ; while ( n % i == 0 ) { n /= i ; count ++ ; } ans *= count * i ; } } return ans ; } function nMosaicNumbers ( n ) { for ( var i = 1 ; i <= n ; i ++ ) document . write ( mosaic ( i ) + " " ) ; } var n = 10 ; nMosaicNumbers ( n ) ;