Submission details
Task:Alkuluvut
Sender:ArktinenKarpalo
Submission time:2025-09-27 11:26:30 +0300
Language:C++ (C++17)
Status:READY
Result:17
Feedback
groupverdictscore
#1ACCEPTED17
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2--2, 3details
#3--3details

Code

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

bool isPrime(ll a) {
  if (a == 1)
    return false;
  for (ll i = 2; i * i <= a; i++) {
    if (a % i == 0)
      return false;
  }
  return true;
}

bool isOk(string s) {
  if (s[0] == '0')
    return false;
  return isPrime(atoll(s.c_str()));
}
std::random_device rd;
std::mt19937 g(rd());

string solve(string luvut) {
  int tries = 100;
  while (tries--) {
    string luku;
    for (auto u : luvut)
      luku.push_back(u);
    int lol = max(0, max(1, rand() % 16) - (int)luku.size());
    for (int i = 0; i < lol; i++) {
      luku.push_back(luvut[rand() % luvut.size()]);
    }
    std::shuffle(luvut.begin(), luvut.end(), g);
    if (isOk(luku)) {
      return "YES\n" + luku;
    }
  }
  return "NO";
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    int k;
    cin >> k;
    string luvut(k, '0');
    for (int i = 0; i < k; i++)
      cin >> luvut[i];
    cout << solve(luvut) << "\n";
  }
}

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

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)