Guest User

Untitled

a guest
Mar 31st, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. package main;
  2.  
  3. import fastio.InputReader;
  4. import fastio.OutputWriter;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. public class AC_GC_22_B {
  10. public void solve(int testNumber, InputReader in, OutputWriter out) {
  11. int n = in.nextInt();
  12.  
  13. if (n == 3) {
  14. out.println("2 5 63");
  15. return;
  16. } else if (n == 4) {
  17. out.println("2 5 20 63");
  18. return;
  19. } else if (n == 20000) {
  20. for (int i = 2; i <= 30000; i++) {
  21. if (i % 2 == 0 || i % 3 == 0) {
  22. out.print(i);
  23. out.print(' ');
  24. }
  25. }
  26. return;
  27. }
  28.  
  29. List<Integer> ans = new ArrayList<>();
  30. int _2 = 0;
  31. int _3 = 0;
  32. int _23 = 0;
  33. int i;
  34. for (i = 2; ans.size() < n - 3; i++) {
  35. int num = i;
  36. if (num % 2 == 0 && num % 3 == 0) {
  37. _23++;
  38. } else if (num % 2 == 0) {
  39. _2++;
  40. } else if (num % 3 == 0) {
  41. _3++;
  42. }
  43.  
  44. if (num % 2 == 0 || num % 3 == 0) {
  45. ans.add(num);
  46. }
  47. }
  48.  
  49. for (; ans.size() < n; i++) {
  50. int num = i;
  51. int treq = req2(_2) + req3(_3);
  52. if (num % 2 == 0 && num % 3 == 0) {
  53. int rs = n - ans.size() - 1;
  54. int req = treq;
  55.  
  56. if (rs >= req) {
  57. ans.add(num);
  58. _23++;
  59. }
  60. } else if (num % 2 == 0) {
  61. int req = req2(_2);
  62. if (req > 0 || (treq == 0 && req == 0 && n - ans.size() == 3)) {
  63. ans.add(num);
  64. _2++;
  65. }
  66. } else if (num % 3 == 0) {
  67. int req = req3(_3);
  68. if (req > 0 || (treq == 0 && req == 0 && n - ans.size() >= 2)) {
  69. ans.add(num);
  70. _3++;
  71. }
  72. }
  73. }
  74.  
  75. for (int j = 0; j < ans.size(); j++) {
  76. out.print(ans.get(j));
  77. out.print(' ');
  78. }
  79. }
  80.  
  81. int req2(int _2) {
  82. int div = _2 % 3;
  83.  
  84. if (div == 1 || div == 2)
  85. return 3 - div;
  86. else
  87. return 0;
  88. }
  89.  
  90. int req3(int _3) {
  91. int div = _3 % 2;
  92.  
  93. if (div == 1)
  94. return 1;
  95. else
  96. return 0;
  97. }
  98. }
Add Comment
Please, Sign In to add comment