Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import fastio.InputReader;
- import fastio.OutputWriter;
- import java.util.ArrayList;
- import java.util.List;
- public class AC_GC_22_B {
- public void solve(int testNumber, InputReader in, OutputWriter out) {
- int n = in.nextInt();
- if (n == 3) {
- out.println("2 5 63");
- return;
- } else if (n == 4) {
- out.println("2 5 20 63");
- return;
- } else if (n == 20000) {
- for (int i = 2; i <= 30000; i++) {
- if (i % 2 == 0 || i % 3 == 0) {
- out.print(i);
- out.print(' ');
- }
- }
- return;
- }
- List<Integer> ans = new ArrayList<>();
- int _2 = 0;
- int _3 = 0;
- int _23 = 0;
- int i;
- for (i = 2; ans.size() < n - 3; i++) {
- int num = i;
- if (num % 2 == 0 && num % 3 == 0) {
- _23++;
- } else if (num % 2 == 0) {
- _2++;
- } else if (num % 3 == 0) {
- _3++;
- }
- if (num % 2 == 0 || num % 3 == 0) {
- ans.add(num);
- }
- }
- for (; ans.size() < n; i++) {
- int num = i;
- int treq = req2(_2) + req3(_3);
- if (num % 2 == 0 && num % 3 == 0) {
- int rs = n - ans.size() - 1;
- int req = treq;
- if (rs >= req) {
- ans.add(num);
- _23++;
- }
- } else if (num % 2 == 0) {
- int req = req2(_2);
- if (req > 0 || (treq == 0 && req == 0 && n - ans.size() == 3)) {
- ans.add(num);
- _2++;
- }
- } else if (num % 3 == 0) {
- int req = req3(_3);
- if (req > 0 || (treq == 0 && req == 0 && n - ans.size() >= 2)) {
- ans.add(num);
- _3++;
- }
- }
- }
- for (int j = 0; j < ans.size(); j++) {
- out.print(ans.get(j));
- out.print(' ');
- }
- }
- int req2(int _2) {
- int div = _2 % 3;
- if (div == 1 || div == 2)
- return 3 - div;
- else
- return 0;
- }
- int req3(int _3) {
- int div = _3 % 2;
- if (div == 1)
- return 1;
- else
- return 0;
- }
- }
Add Comment
Please, Sign In to add comment