题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5833
Description
Zhu and 772002 are both good at math. One day, Zhu wants to test the ability of 772002, so he asks 772002 to solve a math problem.
But 772002 has a appointment with his girl friend. So 772002 gives this problem to you.
There are n numbers a1,a2,...,an. The value of the prime factors of each number does not exceed 2000, you can choose at least one number and multiply them, then you can get a number b.
How many different ways of choices can make b is a perfect square number. The answer maybe too large, so you should output the answer modulo by 1000000007.
Input
First line is a positive integer T , represents there are T test cases.
For each test case:
First line includes a number n(1≤n≤300),next line there are n numbers a1,a2,...,an,(1≤ai≤1018).
Output
For the i-th test case , first output Case #i: in a single line.
Then output the answer of i-th test case modulo by 1000000007.
Sample Input
2
3
3 3 4
3
2 2 2
Sample Output
Case #1:
3
Case #2:
3
Source
2016中国大学生程序设计竞赛 - 网络选拔赛
题意:
给出n个数,求有多少种方式使得选取的数的乘积是一个完全平方数.
题解:
原题:UVA11542 (大白书P160例题25)
转化成异或方程组,并用高斯消元求解矩阵的秩.
很遗憾,上述知识点都不会....
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <list>
#define LL long long
#define eps 1e-8
#define maxn 2100
#define mod 1000000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
typedef long long ll;
using namespace std;
typedef int Matrix[maxn][maxn];
int prime[maxn], vis[maxn];
Matrix A;
int get_primes(int m) {
memset(vis, 0, sizeof(vis));
int cnt = 0;
for (int i = 2; i < m; i++) {
if (!vis[i]) {
prime[cnt++] = i;
for (int j = i * i; j < m; j += i)
vis[j] = 1;
}
}
return cnt;
}
int gauss(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;
}
LL quickmod(LL a,LL b,LL m)
{
LL ans = 1;
while(b){
if(b&1){
ans = (ans*a)%m;
b--;
}
b/=2;
a = a*a%m;
}
return ans;
}
int main() {
//freopen("in.txt", "r", stdin);
int m = get_primes(2100);
int t;
int ca = 1;
scanf("%d", &t);
while (t--) {
printf("Case #%d:\n", ca++);
int n, maxp = 0;;
ll x;
scanf("%d", &n);
memset(A, 0, sizeof(A));
for (int i = 0; i < n; i++) {
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 = gauss(A, maxp+1, n);
LL ans = quickmod(2, (LL)(n-r), mod) - 1;
//printf("%lld\n", (1LL << (n-r)) - 1);
printf("%lld\n", ans);
}
return 0;
}