Submission details
Task:Alkuluvut
Sender:jubidubi
Submission time:2025-09-28 21:29:15 +0300
Language:C++ (C++11)
Status:READY
Result:17
Feedback
groupverdictscore
#1ACCEPTED17
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#20.03 s2, 3details
#30.06 s3details

Compiler report

input/code.cpp: In function 'll make_num(std::vector<long long int>&)':
input/code.cpp:16:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   for (ll i = 0; i < v.size(); ++i) {
      |                  ~~^~~~~~~~~~

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

bool is_prime(ll x) {
  if (x <= 1) return false;
  for (ll c = 2; c * c <= x; ++c) {
    if (x % c == 0) return false;
  }
  return true;
}

ll make_num(vector<ll> &v) {
  ll x = 0;
  ll pwr = 1;
  for (ll i = 0; i < v.size(); ++i) {
    x += pwr * v[i];
    pwr *= 10;
  }
  return x;
}

void solve() {
  int n;
  cin >> n;

  vector<ll> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];

  for (int mxln = 0; mxln <= 13 - n; ++mxln) {
    for (int t = 0; t < 100; ++t) {
      vector<ll> tmp;
      for (int x : v) tmp.push_back(x);

      for (int i = 0; i < mxln; ++i) {
        int j = rand() % n;
        tmp.push_back(v[j]);
      }

      random_shuffle(tmp.begin(), tmp.end());

      if (v.back() == 0) continue;

      ll num = make_num(tmp);
      if (is_prime(num)) {
        cout << "YES" << endl;
        cout << num << endl;
        return;
      }
    }
  }

  cout << "NO" << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int ttt;
  cin >> ttt;
  while (ttt--) solve();
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
10
1
0
1
1
...

correct output
NO
YES
11
YES
2
...

user output
NO
YES
11
YES
2
...

Test 2

Group: 2, 3

Verdict:

input
175
1
0
1
1
...

correct output
NO
YES
11
YES
2
...

user output
NO
YES
11
YES
2
...

Test 3

Group: 3

Verdict:

input
848
4
0 1 2 3
4
0 1 2 4
...

correct output
YES
10223
YES
4021
YES
...

user output
YES
20123
YES
421
YES
...