Submission #979277

# Submission time Handle Problem Language Result Execution time Memory
979277 2024-05-10T13:03:35 Z MilosMilutinovic Lutrija (COCI19_lutrija) C++14
70 / 70
573 ms 600 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b;
  cin >> a >> b;
  auto Prime = [&](long long x) {
    if (x <= 1) {
      return false;
    }
    for (int i = 2; i * 1LL * i <= x; i++) {
      if (x % i == 0) {
        return false;
      }
    }
    return true;
  };
  vector<long long> f(1, 2);
  for (int i = -2; i <= 2; i++) {
    if (Prime(a + i)) {
      f.push_back(a + i);
    }
    if (Prime(b + i)) {
      f.push_back(b + i);
    }
  }
  sort(f.begin(), f.end());
  f.erase(unique(f.begin(), f.end()), f.end());
  do {
    int pa, pb;
    for (int i = 0; i < (int) f.size(); i++) {
      if (f[i] == a) {
        pa = i;
      }
      if (f[i] == b) {
        pb = i;
      }
    }
    if (pa <= pb) {
      bool ok = true;
      for (int i = pa; i < pb; i++) {
        if (!Prime(abs(f[i] - f[i + 1]))) {
          ok = false;
          break;
        }
      }
      if (ok) {
        cout << pb - pa + 1 << '\n';
        for (int i = pa; i <= pb; i++) {
          cout << f[i] << " ";
        }
        cout << '\n';
        return 0;
      }
    }
  } while (next_permutation(f.begin(), f.end()));
  cout << -1 << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 444 ms 348 KB Output is correct
2 Correct 190 ms 596 KB Output is correct
3 Correct 313 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 503 ms 448 KB Output is correct
2 Correct 165 ms 428 KB Output is correct
3 Correct 226 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 573 ms 428 KB Output is correct
2 Correct 205 ms 432 KB Output is correct
3 Correct 208 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 460 ms 348 KB Output is correct
2 Correct 140 ms 596 KB Output is correct
3 Correct 73 ms 432 KB Output is correct