Ludic Numbers | Java 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
import java . util . ArrayList ; import java . util . List ; public class Ludic { public static List < Integer > getLudic ( int n ) { List < Integer > ludics = new ArrayList < Integer > ( n ) ; for ( int i = 1 ; i <= n ; i ++ ) ludics . add ( i ) ; for ( int index = 1 ; index < ludics . size ( ) ; index ++ ) { int first_ludic = ludics . get ( index ) ; int remove_index = index + first_ludic ; while ( remove_index < ludics . size ( ) ) { ludics . remove ( remove_index ) ; remove_index = remove_index + first_ludic - 1 ; } } return ludics ; } public static void main ( String [ ] srgs ) { int n = 25 ; System . out . println ( getLudic ( n ) ) ; } }