Ultraviolet A 11542, uva11542
Ultraviolet A 11542-Square
Question Link
Q: given some numbers, make sure that these numeric quality factors do not exceed 500. Find the number of these numbers, and the product is the complete number. There are several selection methods.
Idea: After dividing each number into a quality factor, we find that if the number is a full limit, the number of each quality factor in the selected number must be an even number, in this way, each prime factor can list an exclusive or equation. If the number contains a prime factor, this unknown number exists. Then, Gaussian deyuan is used to obtain the number of free variables, each free variable can be selected or not selected. In this case (2 ^ number), the answer is the one that deducts nothing.
Code:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const long long N = 501;int t, n, a[N][N], Max, vis[N], pn = 0;long long prime[N];void get_prime() { for (long long i = 2; i < N; i++) {if (vis[i]) continue;prime[pn++] = i;for (long long j = i * i; j < N; j += i) vis[j] = 1; }}int gauss() { int i = 0, j = 0; while (i <= Max && j < n) {int k = i;for (; k <= Max; k++) if (a[k][j]) break;if (k != Max + 1) { for (int l = 0; l <= n; l++)swap(a[i][l], a[k][l]); for (int k = i + 1; k <= Max; k++) {if (a[k][j]) { for (int l = j; l <= n; l++)a[k][l] ^= a[i][l];} } i++;}j++; } return n - i;}int main() { get_prime(); scanf("%d", &t); while (t--) {scanf("%d", &n);long long x;Max = 0;memset(a, 0, sizeof(a));for (int i = 0; i < n; i++) { scanf("%lld", &x); for (int j = 0; j < pn && prime[j] <= x; j++) {while (x % prime[j] == 0) { a[j][i] ^= 1; Max = max(Max, j); x /= prime[j];} }}printf("%lld\n", (1LL<<(gauss())) - 1); } return 0;}