Submission details
Task:Alkuluvut
Sender:jubidubi
Submission time:2025-09-28 21:16:16 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.00 s1, 2, 3details
#20.15 s2, 3details
#3--3details

Compiler report

input/code.cpp: In function 'll make_num(std::vector<long long int>&, ll, ll, int)':
input/code.cpp:15: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]
   15 |   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) {
  for (ll c = 2; c * c <= x; ++c) {
    if (x % c == 0) return false;
  }
  return true;
}

ll make_num(vector<ll> &v, ll xi, ll xv, int count) {
  ll x = 0;
  ll pwr = 1;
  for (ll i = 0; i < v.size(); ++i) {
    x += pwr * v[i];
    pwr *= 10;

    if (i == xi) {
      while (count--) {
        x += pwr * xv;
        pwr *= 10;
      }
    }
  }
  return x;
}

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

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

  if (n == 1) {
    if (v[0] == 1) {
      cout << "YES" << endl;
      cout << 11 << endl;
      return;
    }

    if (is_prime(v[0])) {
      cout << "YES" << endl;
      cout << v[0] << endl;
    } else {
      cout << "NO" << endl;
    }
    return;
  }

  if (n == 2 && (v[0] == 0 || v[1] == 0)) {
    cout << "NO" << endl;
    return;
  }

  set<int> s;
  for (int x : v) s.insert(x);
  int l = -1;
  if (s.count(1)) l = 1;
  else if (s.count(7)) l = 7;
  else if (s.count(3)) l = 3;
  else if (s.count(9)) l = 9;

  if (l == -1) {
    cout << "NO" << endl;
    return;
  }

  v.push_back(l);
  reverse(v.begin(), v.end());

  for (int i = 0; i < n; ++i) {
    for (int x : v) {
      for (int count = 1; count < 13 - n; ++count) {
        ll num = make_num(v, i, x, count);
        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:

input
10
1
0
1
1
...

correct output
NO
YES
11
YES
2
...

user output
YES
0
YES
11
YES
...

Test 2

Group: 2, 3

Verdict:

input
175
1
0
1
1
...

correct output
NO
YES
11
YES
2
...

user output
YES
0
YES
11
YES
...

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
(empty)