Zhu and 772002
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1862 Accepted Submission(s): 656
Problem 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 .
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) .
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 .
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
Author
UESTC
Source
Recommend
wange2014
题意:给出n个数字,问有多少种方式取(1~n)个数字使得成为一个完美平方数
解题思路:一个数字分解后,可以用01表示分解后每种素数的个数,然后再用n个01变量xi来表示是否选择这个数,其中xi表示选第i个数,xi表示不选它,则可以对每个素数的幂列出一个模2的方程,有因为任意变量的系数非0即1,所以可以把方程组转化为xor方程组,然后对xor方程组进行消元,假设最后自由变量f个,则线性方程组的解共有2的f次方个。因本题不允许一个整数都不选,则最终答案减一。
白书原题P160
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
const LL mod = 1000000007;
int a[500],visit[5005];
int v[500][500];
int n,cnt,sum,r;
void init()
{
memset(visit, 1, sizeof visit);
visit[0] = visit[1] = 0;
for (int i = 2; i <= 2000; i++)
{
if (visit[i])
{
for (int j = 2 * i; j <= 2000; j += i)
visit[j] = 0;
}
}
cnt = 0;
for (int i = 0; i < 2000; i++)
if (visit[i]) a[cnt++] = i;
}
void Swap(int x, int y)
{
if (x == y) return;
for (int i = 0; i < n; i++)
swap(v[x][i], v[y][i]);
}
void check(int x, int y)
{
for (int i = x; i < cnt; i++)
{
if (v[i][y] != 0)
{
Swap(x, i);
break;
}
}
}
void fxor(int x, int y)
{
for (int i = 0; i < n; i++)
v[y][i] = v[x][i] ^ v[y][i];
}
void f(int x, int y)
{
for (int i = x + 1; i < cnt; i++)
if (v[i][y] != 0) fxor(x, i);
}
LL getsum(LL x,LL y)
{
LL ans = 1;
while (y)
{
if (y % 2 == 1) ans = (ans * x) % mod;
y >>= 1;
x = (x * x) % mod;
}
return ans;
}
int main()
{
init();
int t, cas = 0;
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
memset(v, 0, sizeof(v));
for (int i = 0; i < n; i++)
{
LL x;
scanf("%lld", &x);
int res = 0;
while (x != 1)
{
if (x%a[res] == 0)
{
v[res][i]++;
x /= a[res];
}
else res++;
}
}
for (int i = 0; i < cnt; i++)
for (int j = 0; j < n; j++)
v[i][j] %= 2;
r = 0;
for (int i = 0; i < n; i++)
{
check(r, i);
if (v[r][i] != 0)
{
f(r, i);
r++;
}
}
r = n - r;
LL ans=getsum(2, r) - 1;
printf("Case #%d:\n%lld\n", ++cas, ans);
}
return 0;
}