Given an integer N, the task is to print first N Mosaic numbers. A Mosaic number can be expressed as follows:
If N = p1a1p2a2…pkak in the prime facrorization of N
where p1 ,p2 … pk are prime numbers.
Then the Nth Mosaic number is equal to ((p1)*(a1))*((p2)*(a2))*…*((pk)*(ak))
Input : N=10
Output : 1 2 3 4 5 6 7 6 6 10
For N = 4, N = 22 .
4th Mosaic number = 2*2 = 4
For N=8 , N= 2 3
8th Mosaic number = 2*3 = 6
Similarly print first N Mosaic numbers
Input : N=5
Output : 1 2 3 4 5
Run a loop from 1 to N and for every i we have to find all the prime factors and also the powers of the factors in the number by dividing the number by the factor until the factor divides the number. The ith Mosaic number will then be the product of the found prime factors and their powers.
Below is the implementation of the above approach:
1 2 3 4 5 6 7 6 6 10
- Find the Nth Mosaic number
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Program to print non square numbers
- Print all integers that are sum of powers of two given numbers
- Print n numbers such that their sum is a perfect square
- Program to print first N Prime numbers
- Print squares of first n natural numbers without using *, / and -
- Print all Good numbers in given range
- Print the kth common factor of two numbers
- Program to print first n Fibonacci Numbers | Set 1
- Print prime numbers in a given range using C++ STL
- Print all numbers less than N with at-most 2 unique digits
- Print k numbers where all pairs are divisible by m
- Print first n Fibonacci Numbers using direct formula
- Print prime numbers from 1 to N in reverse order
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.