This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
using namespace std;
int gcd (int a, int b) { return b == 0 ? a : gcd(b, a%b); }
int n, a[2225], g[2225][2225], w[2225], c;
bool used[2225];
int res;
void solve (int x) {
if(x == n) {
for(int i = 0; i < n; i++) if(i < c){
for(int j = i+1; j < n; j++) if(j < c) {
if(gcd(a[w[i]], a[w[j]]) > 1) return;
}
}
++res;
return;
}
solve(x+1);
w[c++] = x;
solve(x+1);
w[--c] = 0;
}
int main() {
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%d", a+i);
for(int i = 0; i < n; i++) {
for(int j = i+1; j < n; j++) {
g[i][j] = g[j][i] = gcd(a[i], a[j]);
}
}
if(n <= 20)solve(0);
res -= n+1;
printf("%d\n", res);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |