fork download
  1. import java.util.*;
  2. class M{
  3. static List c(int n){
  4. List<Integer> l = new ArrayList();
  5. int i = 1;
  6. for(; i++ < n; l.add(i));
  7. for(i = 1; i++ < n;){
  8. for(int x : l){
  9. if(i != x & x%i < 1 & l.indexOf(i) >= 0){
  10. l.remove((Integer)i);
  11. l.remove((Integer)x);
  12. break;
  13. }
  14. }
  15. }
  16. return l;
  17. }
  18.  
  19. public static void main(String[] a){
  20. System.out.println(Arrays.toString(c(2).toArray()));
  21. System.out.println(Arrays.toString(c(6).toArray()));
  22. System.out.println(Arrays.toString(c(15).toArray()));
  23. System.out.println(Arrays.toString(c(20).toArray()));
  24. System.out.println(Arrays.toString(c(22).toArray()));
  25. }
  26. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
[2]
[5]
[8, 9, 11, 12, 13, 15]
[11, 12, 13, 15, 17, 19, 20]
[12, 13, 15, 17, 19, 20, 21]