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
using System ; using System . Collections ; class GFG { public static ArrayList getLudic ( int n ) { ArrayList ludics = new ArrayList ( ) ; for ( int i = 1 ; i <= n ; i ++ ) ludics . Add ( i ) ; for ( int index = 1 ; index < ludics . Count ; index ++ ) { int first_ludic = ( int ) ludics [ index ] ; int remove_index = index + first_ludic ; while ( remove_index < ludics . Count ) { ludics . Remove ( ludics [ remove_index ] ) ; remove_index = remove_index + first_ludic - 1 ; } } return ludics ; } 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 ( " ] " ) ; } }