Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
Try not to let the title bait you. You do not need to run a sieve here.
The target product is very small and very specific: .
Think about the factorization of . What positive integers can multiply together to make it?
Since is prime, every selected number must be either or .
So the answer is YES exactly when the array contains at least one 67; choose that element alone.
Research check: the official Codeforces problem, the Codeforces Round 1080 editorial, Arpa's tutorial page linking an accepted submission, and public accepted-style solutions all point to the same intended approach: just check whether 67 appears. The community explanation also frames the same prime-number observation. No need to cosplay as Eratosthenes.
We need to choose a non-empty subset of the given positive integers so that its product is exactly .
The key fact is:
So its only positive divisors are:
Suppose some selected subset has product . Pick any selected number . Since all numbers are positive integers, we can write:
where is the product of the other selected numbers, also a positive integer. Therefore must divide . Since is prime, must be either or .
That immediately kills the common false assumption: numbers like , , , or are not helpful. They don't combine into because has no nontrivial factorization. It's prime; the problem title is basically trolling.
Now there are two cases:
YES.NO.The sample's first test has a 67, so YES. The note selects , but selecting only already works. In the second test there is no 67, so no subset can reach the target.
Edge cases:
[67]: YES.[1]: NO because the subset must be non-empty and product is .67: YES.Algorithm:
For each test case, scan the numbers and remember whether any value equals .
Complexity per test case:
Memory:
With , this is wildly under the limit. The CPU is basically on vacation.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
bool ok = false;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x == 67) ok = true;
}
cout << (ok ? "YES" : "NO") << '\n';
}
return 0;
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
bool ok = false;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x == 67) ok = true;
}
cout << (ok ? "YES" : "NO") << '\n';
}
return 0;
}