Skip to content

Instantly share code, notes, and snippets.

@hikariyo
Created December 27, 2025 12:33
Show Gist options
  • Select an option

  • Save hikariyo/ca9478f955e40363ed9a7fef639f5114 to your computer and use it in GitHub Desktop.

Select an option

Save hikariyo/ca9478f955e40363ed9a7fef639f5114 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int N = 150;
int a[N];
bitset<N> st;
vector<int> primes;
set<int> exclude[N];
void init(int n) {
for (int i = 2; i <= n; i++) {
if (!st[i]) primes.pb(i);
for (int j = 0; i * primes[j] <= n; j++) {
st[i * primes[j]] = 1;
if (i % primes[j] == 0) break;
}
}
}
bool solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a+1, a+1+n);
for (int i = 1; i < n; i++) {
if (a[i] == a[i+1]) return false;
}
for (int p: primes) exclude[p].clear();
for (int i = 1; i <= n; i++) {
for (int j = i+1; j <= n; j++) {
for (int p: primes) {
if ((a[j] - a[i]) % p != 0) continue;
int ex = ((-a[i]) % p + p) % p;
exclude[p].insert(ex);
}
}
}
for (int p: primes) {
if (exclude[p].size() == p) return false;
}
return true;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
init(N-1);
int T;
cin >> T;
while (T--) cout << (solve() ? "YES" : "NO") << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment