Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public class P82{
  2. final static int n=1000;
  3. static int lastProcessed=-1;
  4. static int freePlace =0;
  5. static int [] container=new int [n];
  6. static boolean [] mark=new boolean [n];
  7. static void add ( int a ){
  8. if ( freePlace <n )
  9. { container [freePlace]=a;
  10. freePlace ++;
  11. }
  12. }
  13. static boolean Empty ( )
  14. {return (( freePlace-lastProcessed)==1) ; }
  15. static void process ()
  16. {
  17. int a ;
  18. lastProcessed++;
  19. a=container[lastProcessed] ;
  20. if ( a<n ) mark [ a]=true ;
  21. if ( 2*a+1<n) add (2*a+1) ;
  22. if ( 3*a<n) add (3*a);
  23. }
  24. public static void main(String[] args) {
  25. int i ;
  26. for ( i =0;i<n ; i++)
  27. mark [ i ]= false ;
  28. add (1) ;
  29. while ( ! Empty ( ) )
  30. process () ;
  31. for ( i =0;i<n ; i++)
  32. { if (mark [ i ] )
  33. System.out.print ( i+" " ) ; }
  34. System.out.println ( "" ) ;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement