Ludic numbers are obtained by considering list of natural numbers (starting from 2) and removing i-th number in i-th iteration (where i begins with 2). In every iteration, the first removed number is Ludic. 1 is considered as Ludic.

Process of generating Ludic numbers :

Ludic = {1, …}

Consider natural numbers from 2,

2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 …Delete every 2nd number

3, 5, 7, 9, 11, 13, 15, 17, 19, 21 ..The first deleted number is 2.

Ludic = {1, 2, …}Delete every 3rd number.

5, 7, 11, 13, 17, 19, 22 ..

The first deleted number is 3

Ludic = {1, 2, 3, …}Delete every 4th number.

5, 7, 11, 13, 17, 19, 22 ..The first deleted number is 5

Ludic = {1, 2, 3, 5, ..}This process continues..

The process is similar to the Sieve of Eratosthenes.

Given a number n, print all Ludic numbers smaller than or equal to n.

**Examples : **

Input : n = 10 Output : 1, 2, 3, 5, 7 Input : n = 25 Output : 1, 2, 3, 5, 7, 11, 13, 17, 23, 25

The idea to print Ludic Numbers is simple. We create a list of sizes and use the above-illustrated process. In each iteration, we delete every i-th number, we do not delete the current first number so that we can return it later.

## C++

`// C++ code to print Lucid ` `// number smaller than or ` `// equal to n. ` `#include <bits/stdc++.h>` `using` `namespace` `std;` `// Returns a list containing ` `// all Ludic numbers smaller ` `// than or equal to n. ` `vector<` `int` `> getLudic(` `int` `n) ` `{ ` ` ` `// ludics list contain all ` ` ` `// the ludic numbers ` ` ` `vector<` `int` `> ludics; ` ` ` ` ` `for` `(` `int` `i = 1; i <= n; i++) ` ` ` `ludics.push_back(i); ` ` ` `// Here we have to start with ` ` ` `// index 1 and will remove nothing ` ` ` `// from the list ` ` ` `for` `(` `int` `index = 1; index < ludics.size(); index++) ` ` ` `{ ` ` ` `// Here first item should be included in the list ` ` ` `// and the deletion is refered by this first item ` ` ` `// in the loop . ` ` ` `int` `first_ludic = ludics[index];` ` ` `// Remove_index variable is used to store ` ` ` `// the next index which we want to delete ` ` ` `int` `remove_index = index + first_ludic; ` ` ` ` ` `while` `(remove_index < ludics.size()) ` ` ` `{ ` ` ` `// Removing the next item ` ` ` `auto` `it = ludics.begin();` ` ` `it = it + remove_index;` ` ` `ludics.erase(it); ` ` ` `// Remove_index is updated so that ` ` ` `// we get the next index for deletion ` ` ` `remove_index = remove_index + first_ludic - 1; ` ` ` `} ` ` ` `} ` ` ` `return` `ludics; ` `} ` ` ` `// Driver code` `int` `main()` `{` ` ` `int` `n = 25; ` ` ` `vector<` `int` `> ans = getLudic(n);` ` ` `cout << ` `"["` `;` ` ` ` ` `for` `(` `int` `i = 0; i < ans.size() - 1; i++) ` ` ` `{` ` ` `cout << ans[i] << ` `", "` `;` ` ` `}` ` ` ` ` `cout << ans[ans.size() - 1] << ` `"]"` `; ` ` ` `return` `0;` `}` `// This code is contributed by divyeshrabadiya07` |

*chevron_right*

*filter_none*

## Java

`// Java code to print Lucid number smaller than` `// or equal to n.` `import` `java.util.ArrayList;` `import` `java.util.List;` `public` `class` `Ludic {` ` ` `// Returns a list containing all Ludic numbers` ` ` `// smaller than or equal to n.` ` ` `public` `static` `List<Integer> getLudic(` `int` `n)` ` ` `{` ` ` `// ludics list contain all the ludic numbers` ` ` `List<Integer> ludics = ` `new` `ArrayList<Integer>(n);` ` ` `for` `(` `int` `i = ` `1` `; i <= n; i++) ` ` ` `ludics.add(i);` ` ` ` ` `// Here we have to start with index 1 and will remove nothing` ` ` `// from the list` ` ` `for` `(` `int` `index = ` `1` `; index < ludics.size(); index++) {` ` ` `// Here first item should be included in the list` ` ` `// and the deletion is refered by this first item` ` ` `// in the loop .` ` ` `int` `first_ludic = ludics.get(index);` ` ` `// remove_index variable is used to store` ` ` `// the next index which we want to delete` ` ` `int` `remove_index = index + first_ludic;` ` ` `while` `(remove_index < ludics.size()) {` ` ` `// removing the next item` ` ` `ludics.remove(remove_index);` ` ` `// remove_index is updated so that` ` ` `// we get the next index for deletion` ` ` `remove_index = remove_index + first_ludic - ` `1` `;` ` ` `}` ` ` `}` ` ` `return` `ludics;` ` ` `}` ` ` `public` `static` `void` `main(String[] srgs)` ` ` `{` ` ` `int` `n = ` `25` `;` ` ` `System.out.println(getLudic(n));` ` ` `}` `}` |

*chevron_right*

*filter_none*

## Python3

`# Python3 code to print Lucid ` `# number smaller than or equal ` `# to n.` `# Returns a list containing all ` `# Ludic numbers smaller than ` `# or equal to n.` `def` `getLudic(n):` ` ` `# ludics list contain all ` ` ` `# the ludic numbers` ` ` `ludics ` `=` `[]` ` ` `for` `i ` `in` `range` `(` `1` `, n ` `+` `1` `):` ` ` `ludics.append(i)` ` ` `# Here we have to start with ` ` ` `# index 1 and will remove ` ` ` `# nothing from the list` ` ` `index ` `=` `1` ` ` `while` `(index !` `=` `len` `(ludics)):` ` ` `# Here first item should be ` ` ` `# included in the list and ` ` ` `# the deletion is refered ` ` ` `# by this first item` ` ` `# in the loop .` ` ` `first_ludic ` `=` `ludics[index]` ` ` `# Remove_index variable is used ` ` ` `# to store the next index which ` ` ` `# we want to delete` ` ` `remove_index ` `=` `index ` `+` `first_ludic` ` ` `while` `(remove_index < ` `len` `(ludics)):` ` ` `# Removing the next item` ` ` `ludics.remove(ludics[remove_index])` ` ` `# Remove_index is updated so that` ` ` `# we get the next index for deletion` ` ` `remove_index ` `=` `remove_index ` `+` `first_ludic ` `-` `1` ` ` `index ` `+` `=` `1` ` ` `return` `ludics` `# Driver code ` `n ` `=` `25` `print` `(getLudic(n))` `# This code is contributed by avanitrachhadiya2155` |

*chevron_right*

*filter_none*

## C#

`// C# code to print Lucid number smaller` `// than or equal to n. ` `using` `System; ` `using` `System.Collections;` `class` `GFG{ ` `// Returns a list containing all Ludic` `// numbers smaller than or equal to n. ` `public` `static` `ArrayList getLudic(` `int` `n) ` `{ ` ` ` ` ` `// ludics list contain all the ` ` ` `// ludic numbers ` ` ` `ArrayList ludics = ` `new` `ArrayList(); ` ` ` ` ` `for` `(` `int` `i = 1; i <= n; i++) ` ` ` `ludics.Add(i); ` ` ` ` ` `// Here we have to start with index 1` ` ` `// and will remove nothing from the list ` ` ` `for` `(` `int` `index = 1; ` ` ` `index < ludics.Count;` ` ` `index++)` ` ` `{ ` ` ` ` ` `// Here first item should be included` ` ` `// in the list and the deletion is` ` ` `// refered by this first item in the` ` ` `// loop . ` ` ` `int` `first_ludic = (` `int` `)ludics[index]; ` ` ` `// remove_index variable is used to store ` ` ` `// the next index which we want to delete ` ` ` `int` `remove_index = index + first_ludic; ` ` ` ` ` `while` `(remove_index < ludics.Count) ` ` ` `{ ` ` ` ` ` `// Removing the next item ` ` ` `ludics.Remove(ludics[remove_index]); ` ` ` `// remove_index is updated so that ` ` ` `// we get the next index for deletion ` ` ` `remove_index = remove_index + ` ` ` `first_ludic - 1; ` ` ` `} ` ` ` `} ` ` ` `return` `ludics; ` `} ` `// Driver code ` `public` `static` `void` `Main(` `string` `[] srgs) ` `{ ` ` ` `int` `n = 25; ` ` ` ` ` `ArrayList tmp = getLudic(n);` ` ` ` ` `Console.Write(` `"["` `);` ` ` `foreach` `(` `int` `x ` `in` `tmp)` ` ` `{` ` ` `Console.Write(x + ` `", "` `);` ` ` `}` ` ` `Console.Write(` `"]"` `);` `} ` `} ` `// This code is contributed by rutvik_56` |

*chevron_right*

*filter_none*

**Output: **

[1, 2, 3, 5, 7, 11, 13, 17, 23, 25]

**References :**

https://oeis.org/wiki/Ludic_numbers

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.

## Recommended Posts:

- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Count numbers which can be constructed using two numbers
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Numbers less than N which are product of exactly two distinct prime numbers
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Count numbers which are divisible by all the numbers from 2 to 10
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- Check if a given pair of Numbers are Betrothed numbers or not
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- Count of numbers upto M divisible by given Prime Numbers
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Maximize count of equal numbers in Array of numbers upto N by replacing pairs with their sum
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Ugly Numbers
- Count of Binary Digit numbers smaller than N
- Program for Fibonacci numbers
- Average of a stream of numbers
- Add two numbers without using arithmetic operators

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.