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