Source: Light OJ 1288 subsets Forming Perfect Squares
Test instructions: Give you the number of N to select some numbers their product is the total squared number of how many schemes
Idea: Each number decomposition factor can be selected or not to choose 0 1 means that the number of elements selected by the M prime factor must be an even
Each row of matrices that comprise a M-row and N-column represents the number of free elements for each factor's coefficients
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std;
const int MAXN = 1010;
const int mod = 1000000007;
typedef int MATRIX[MAXN][MAXN];
typedef long Long LL;
int PRIME[MAXN];
BOOL VIS[MAXN];
return a^p mod n fast power ll Pow_mod (ll A, ll P, ll N) {ll ans = 1;
while (p) {if (p&1) {ans *= A;
Ans%= N;
} a *= A;
a%= N;
P >>= 1;
} return ans;
} void Sieve (int n) {int m = sqrt (n+0.5);
memset (Vis, 0, sizeof (VIS));
Vis[0] = vis[1] = 1;
for (int i = 2, I <= m; i++) if (!vis[i]) for (int j = i*i; J <= N; j + = i) vis[j] = 1;
} int Get_primes (int n) {sieve (n);
int c = 0;
for (int i = 2; I <= n; i++) if (!vis[i]) prime[c++] = i;
return C;
} int Rank (Matrix A, int m, int n) {int i = 0, j = 0, K, R, U;
while (I < m && J < n) {r = i;
for (k = i; k < m; k++) if (A[k][j]) {r = k;
Break } if (A[r][j]) {if (r! = i) for (k = 0; K <= N;
k++) Swap (A[r][k], a[i][k]);
for (U = i+1, u < m; u++) if (A[u][j]) for (k = i; k <= n; k++) a[u][k] ^= a[i][k];
i++;
} j + +;
} return i;
} Matrix A;
int main () {int cas = 1;
int m = get_primes (500);
int T;
scanf ("%d", &t);
while (t--) {int n, MAXP = 0;
scanf ("%d", &n);
memset (A, 0, sizeof (a));
for (int i = 0; i < n; i++) {Long long x;
scanf ("%lld", &x);
for (int j = 0; J < m; J + +) {while (x% prime[j] = = 0) {MAXP = max (Maxp, J);
x/= prime[j];
A[j][i] ^= 1;
}}} int r = Rank (A, maxp+1, N);
printf ("Case%d:%lld\n", cas++, Pow_mod (2, N-r, MoD)-1);
} return 0; }