Given a number n, generate a list of n composite numbers.
Input : 5 Output : 122, 123, 124, 125 Input : 10 Output : 3628802, 3628803, 3628804, 3628805, 3628806, 3628807, 3628808, 3628809, 3628810
The idea here is using the properties of . Since , then numbers , all divide . Therefore is divisible by 2, is divisible by 3 ….. is divisible by n. And by above pattern they are consecutive composites.
We find (n+1)!, then we print numbers (n+1)! + 2, (n+1)! + 3, …. (n+1)! + (n + 1).
Below is the implementation of above approach:
122 123 124 125
The above solution causes overflow very soon (for small values of n). We can use technique to find factorial of large number to avoid overflow.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Generate a Binary String without any consecutive 0's and at most K consecutive 1's
- Find a range of composite numbers of given length
- Split n into maximum composite numbers
- Sum and Product of all Composite numbers which are divisible by k in an array
- Product of all the Composite Numbers in an array
- Sum and product of k smallest and k largest composite numbers in the array
- Composite numbers with digit sum 1
- Queries for the difference between the count of composite and prime numbers in a given range
- Find a sequence of N prime numbers whose sum is a composite number
- Represent the given number as the sum of two composite numbers
- Find two Composite Numbers such that there difference is N
- Sum of all composite numbers lying in the range [L, R] for Q queries
- Highly Composite Numbers
- Smallest composite number not divisible by first N prime numbers
- Generate original array from difference between every two consecutive elements
- Generate an alternate odd-even sequence having sum of all consecutive pairs as a perfect square
- Interesting facts about Fibonacci numbers
- An interesting solution to get all prime numbers smaller than n
- Composite Number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.