fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. private static long gcd(long a, long b) {
  8. long p = a % b;
  9. if (p == 0L) {
  10. return b;
  11. } else {
  12. return gcd(b, p);
  13. }
  14. }
  15.  
  16. private static void test(final int N) {
  17. long[] list = new long[N];
  18.  
  19. for (int i = 0; i < N; ++i) {
  20. list[i] = (long)(i + 1);
  21. }
  22.  
  23. for (int i = 1; i < N; ++i) {
  24. for (int j =i + 1; j < N; ++j) {
  25. long x = Main.gcd(list[i], list[j]);
  26. long y = (list[i] * list[j]) / x;
  27. list[i] = x;
  28. list[j] = y;
  29. }
  30. }
  31.  
  32. System.out.println("N = " + N);
  33. for (int i= 0; i < N; ++i) {
  34. System.out.print(list[i] + " ");
  35. }
  36. System.out.println();
  37. }
  38.  
  39. public static void main (String[] args) throws java.lang.Exception
  40. {
  41. Main.test(6);
  42. Main.test(20);
  43. }
  44. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
N = 6
1 1 1 2 6 60 
N = 20
1 1 1 1 1 1 1 1 1 1 2 2 2 2 6 12 60 60 2520 232792560