| Task: | Alkuluvut |
| Sender: | tykkipeli |
| Submission time: | 2025-09-27 21:44:44 +0300 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'bool brute(std::vector<long long int>&, ll)':
input/code.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i = 0; i < q.size(); i++) {
| ~~^~~~~~~~~~
input/code.cpp: In function 'void testCase()':
input/code.cpp:61:30: error: expected ';' before string constant
61 | if (!brute(v, base)) cout "NO\n";
| ^~~~~~~
| ;
input/code.cpp:61:26: warning: statement has no effect [-Wunused-value]
61 | if (!brute(v, base)) cout "NO\n";
| ^~~~Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool is_prime(ll x) {
for (ll i = 2; i*i < x; i++) {
if (x%i == 0) return false;
}
return true;
}
bool brute(vector<ll> &v, ll base) {
vector<ll> q;
q.push_back(base);
for (int i = 0; i < q.size(); i++) {
base = q[i];
for (ll x : v) {
ll newbase = base * 10;
newbase += x;
if (newbase > (ll) 1e16) continue;
if (is_prime(newbase)) {
cout << "YES\n";
cout << newbase << "\n";
return true;
}
q.push_back(newbase);
}
}
return false;
}
void testCase() {
int k;
cin >> k;
vector<ll> v;
bool fine = false;
bool fine2 = false;
for (int i = 0; i < k; i++) {
int d;
cin >> d;
if (d%3 != 0) fine = true;
if (d%2 != 0 && d != 5) fine2 = true;
v.push_back(d);
}
if (!fine || !fine2) {
cout << "NO\n";
return;
}
ll base = 0;
bool haszero = false;
for (ll x : v) {
if (x == 0) {
haszero = true;
} else {
base *= 10;
base += x;
}
}
if (haszero) base *= 10;
if (!brute(v, base)) cout "NO\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int i = 0; i < t; i++) {
testCase();
}
}