| Task: | Alkuluvut |
| Sender: | Laakeri |
| Submission time: | 2025-09-27 11:44:46 +0300 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | 17 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 17 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #2 | WRONG ANSWER | 0.02 s | 2, 3 | details |
| #3 | ACCEPTED | 0.03 s | 3 | details |
Code
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef __int128 lll;
lll powmod(lll a, lll p, lll mod) {
if (p==0) return 1;
if (p%2==0) {
a=powmod(a, p/2, mod);
return (a*a)%mod;
}
return (a*powmod(a, p-1, mod))%mod;
}
bool is_w(ll a, ll even, ll odd, ll p) {
lll u = powmod(a, odd, p);
if (u==1) return 0;
for (ll j=1;j<even;j*=2) {
if (u==p-1) return 0;
u*=u;u%=p;
}
return 1;
}
bool isPrime(ll p) {
if (p==2) return 1;
if (p<=1||p%2==0) return 0;
ll odd=p-1;ll even=1;
while (odd%2==0) {
even*=2;odd/=2;
}
ll b[7]={2, 325, 9375, 28178, 450775, 9780504, 1795265022};
for (ll i=0;i<7;i++) {
ll a=b[i]%p;
if (a==0) return 1;
if (is_w(a, even, odd, p)) return 0;
}
return 1;
}
mt19937 gen(1337);
int getrand(int a, int b){
uniform_int_distribution<int> d(a, b);
return d(gen);
}
void solve(){
int k;
cin>>k;
vector<int> ns(k);
for (int i=0;i<k;i++){
cin>>ns[i];
}
if (k==1 && (ns[0] == 5 || ns[0]==2)){
cout<<"YES"<<endl;
cout<<ns[0]<<endl;
return;
}
sort(ns.begin(), ns.end());
int allbad = 1;
for (int n : ns) {
if (n % 2 != 0 && n % 5 != 0){
allbad = 0;
}
}
if (allbad){
cout<<"NO"<<endl;
return;
}
for (int le=(int)ns.size();le<16;le++){
for (int its=0;its<100;its++){
vector<int> t=ns;
while ((int)t.size()<le){
t.push_back(ns[getrand(0, k)]);
}
shuffle(t.begin(), t.end(), gen);
if (t[0]==0){
continue;
}
ll num=0;
for (int n : t){
num *= (ll)10;
num += (ll)n;
}
if (isPrime(num)){
cout<<"YES"<<endl;
cout<<num<<endl;
return;
}
}
}
cout<<"NO"<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
for (int tc=0;tc<t;tc++){
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: WRONG ANSWER
| input |
|---|
| 175 1 0 1 1 ... |
| correct output |
|---|
| NO YES 11 YES 2 ... |
| user output |
|---|
| NO YES 11 YES 2 ... Truncated |
Test 3
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 848 4 0 1 2 3 4 0 1 2 4 ... |
| correct output |
|---|
| YES 10223 YES 4021 YES ... |
| user output |
|---|
| YES 22013 YES 4021 YES ... Truncated |
