Zhu and 772002
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1641 Accepted Submission(s): 580
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
题意:
给出n个数字,求解这n个数字相乘得到一个完全平方数的个数有多少
题解:
已知每个数字分解得到最大的因子不会超过2000,就可以先预处理得到2000以内的质数
将所有的数字都分解为质数,统计质数出现的次数,然后进行高斯消元
得到自由变量的个数m
经过分析思考可知答案就是 2^m-1(求解这个用快速幂取模)
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define MAXN 310
#define LL long long
#define mem(a) memset(a,0,sizeof(a))
const LL mod=1000000007;
const double eps=1e-9;
int arr[MAXN][MAXN];
int equ,var;///方程的个数,变量的个数
int prime[MAXN],tot;
const int maxx=2000;
int isprimer[maxx];
void primer()
{
int i,j;
int sqrtmaxx=(int)sqrt((double)maxx);
for(i=2;i<maxx;i++)
isprimer[i]=1;
for(i=2;i<maxx;i++){
if(i<sqrtmaxx)
if(isprimer[i])
for(j=i*i;j<maxx;j+=i)
isprimer[j]=0;
}
for(int i=2;i<maxx;i++)
if(isprimer[i])
prime[tot++]=i;
}
void devide(int k,LL x)
{
for(int i=0;i<tot;i++){
while(x%prime[i]==0)
{
x/=prime[i];
arr[k][i]^=1;
}
if(x<prime[i])
break;
}
}
int abs(int x)
{
if(x<0)
return -x;
return x;
}
int Gauss()
{
int i,j;
int max_r;
int row=0,col=0;
for(;row<equ&&col<var;row++,col++)
{
max_r=row;
for(i=row+1;i<equ; i++)
if(abs(arr[i][col])>abs(arr[max_r][col]))
max_r=i;
if(max_r!=row)
for(i=0;i<var+1;i++)
swap(arr[row][i],arr[max_r][i]);
if(arr[row][col]==0){
row--;
continue;
}
for(i=row+1;i<equ;i++)
if(arr[i][col])
for(j=col;j<var;j++)
arr[i][j]^=arr[row][j];
}
return row;
}
LL multi(LL a,LL b)
{
LL ans=0;
while(b)
{
if(b&1)
ans=(ans+a)%mod;
a=(a+a)%mod;
b>>=1;
}
return ans;
}
LL powmod(LL a,LL b)
{
LL ans=1;
while(b)
{
if(b&1)
ans=multi(ans,a)%mod;
a=multi(a,a)%mod;
b>>=1;
}
return ans;
}
int main()
{
int n,T;
primer();
int cases=1;
//freopen("in.txt","r",stdin);
scanf("%d",&T);
while(T--)
{
LL temp;
mem(arr);
scanf("%d",&n);
equ=n,var=tot;
for(int i=0;i<n;i++){
scanf("%lld",&temp);
devide(i,temp);
}
LL ans=n-Gauss();
ans=powmod(2,ans)-1;
printf("Case #%d:\n%lld\n",cases++,ans);
}
return 0;
}