Zhu and 772002

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.

 
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
 

题意:

  给你n个数,每个数的素数因子最大不超过2000,从n个数取出任意个至少一个,问有多少种方案使得数的乘积为完全平方数。

题解:

  将所有素数处理出来

  答案就是 每种素数个数为偶数个

  将每个素数使用个数设为x 那么最终mod 2 = 0

  那么有303个这样的方程

  高斯消元求解异或方程组

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18;
const double Pi = acos(-1.0);
const int N = 2e3+, M = 1e6, mod = , inf = 2e9; int p[N],H[N],cnt,A[][],mx,ini[N];
LL a[N];
void init() {
for(int i = ; i <= ; ++i) {
if(!H[i]) {
p[cnt++] = i;
for(int j = i+i; j <= ; j += i) {
H[j] = ;
}
}
}
ini[] = ;
for(int i = ; i<= ; ++i) ini[i] = ini[i-]*%mod;
}
LL Guass(int n,int m) {
int i, j;
for(i = , j = ; i < n && j < m; ) {
int x = -;
for(int k = i; k < n; ++k) {
if(A[k][j]) {
x = k;
break;
}
}
if(x == -) {
++j;
continue;
}
for(int k = ; k <= m; ++k) swap(A[i][k],A[x][k]);
for(int u = i+; u < n; ++u) {
if(A[u][j]) {
for(int k = ; k <= m; ++k) {
A[u][k] ^= A[i][k];
}
}
}
++i;
++j;
}
return m-i;
}
int main() {
int T,cas = ,n;
init();
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
mx = ;
for(int i = ; i < n; ++i) scanf("%I64d",&a[i]);
memset(A,,sizeof(A));
for(int i = ; i < n; ++i) {
for(int j = ; j < cnt; ++j) {
while(a[i] % p[j] == ) {
A[j][i] ^= ;
a[i] /= p[j];
mx = max(mx,j+);
}
}
}
printf("Case #%d:\n",cas++);
cout<<ini[Guass(mx,n)] - <<endl;
}
return ;
}

hdu 5833 Zhu and 772002 高斯消元的更多相关文章

  1. HDU - 5833: Zhu and 772002 (高斯消元-自由元)

    pro:给定N个数Xi(Xi<1e18),保证每个数的素因子小于2e3:问有多少种方案,选处一些数,使得数的乘积是完全平方数.求答案%1e9+7: N<300; sol:小于2e3的素数只 ...

  2. HDU 5833 Zhu and 772002

    HDU 5833 Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  3. hdu 5833 Zhu and 772002 ccpc网络赛 高斯消元法

    传送门:hdu 5833 Zhu and 772002 题意:给n个数,每个数的素数因子不大于2000,让你从其中选则大于等于1个数相乘之后的结果为完全平方数 思路: 小于等于2000的素数一共也只有 ...

  4. HDU 5833 Zhu and 772002 (高斯消元)

    Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...

  5. HDU 5755 Gambler Bo(高斯消元)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5755 [题目大意] 一个n*m由0,1,2组成的矩阵,每次操作可以选取一个方格,使得它加上2之后对 ...

  6. HDU 4818 RP problem (高斯消元, 2013年长春区域赛F题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4818 深深地补一个坑~~~ 现场赛坑在这题了,TAT.... 今天把代码改了下,过掉了,TAT 很明显 ...

  7. ACM学习历程—HDU 3949 XOR(xor高斯消元)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...

  8. 2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)

    题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的 ...

  9. HDU 3571 N-dimensional Sphere(高斯消元 数论题)

    这道题算是比较综合的了,要用到扩展欧几里得,乘法二分,高斯消元. 看了题解才做出来orz 基本思路是这样,建一个n*(n-1)的行列式,然后高斯消元. 关键就是在建行列式时会暴long long,所以 ...

随机推荐

  1. atom 折腾记(转载的)

    http://www.bkjia.com/webzh/999078.html

  2. 76 binary_search 查找重复元素

    [本文链接] http://www.cnblogs.com/hellogiser/p/binary-search-for-repeated-element.html [题目] 给定一个升序排列的自然数 ...

  3. jquery checkbox 复选框多次点击判断选中状态,以及全选/取消的代码示例

    2015年12月21日 10:52:51 星期一 目标, 点击当前的checbox, 判断点击后当前checkbox是否是选中状态. html: <input type="checkb ...

  4. 请确认 <Import> 声明中的路径正确,且磁盘上存在该文件。

    在网上下了个源码打开报错. 请确认 <Import> 声明中的路径正确,且磁盘上存在该文件. 一查,原来是路径错误. 解决办法:将项目文件(.csproj)用记事本打开,然后找到<I ...

  5. UVALive 5903 Piece it together(二分图匹配)

    给你一个n*m的矩阵,每个点为'B'或'W'或'.'.然后你有一种碎片.碎片可以旋转,问可否用这种碎片精确覆盖矩阵.N,M<=500 WB  <==碎片 W 题目一看,感觉是精确覆盖(最近 ...

  6. matrix_超时

    问题 H: matrix 时间限制: 1 Sec  内存限制: 256 MB提交: 26  解决: 10[提交][状态][讨论版] 题目描述 给定两个长度为n的整数序列l和t,分别作为n×n矩阵F的第 ...

  7. python MethodType方法详解和使用

    python 中MethodType方法详解和使用 废话不多说,直接上代码 #!/usr/bin/python # -*-coding:utf-8-*- from types import Metho ...

  8. mysql设置密码

    mysql如何设置密码 有很多方法: 1.用root 进入mysql后 mysql>set password =password('你的密码'); mysql>flush privileg ...

  9. August 21st 2016 Week 35th Sunday

    I figure life is a gift and I don't intend on wasting it. 我觉得生命是一份礼物,我不想浪费它. Tonight when I was runn ...

  10. webstorm配置scss自动编译路径

    webstorm支持sass的同步编译,也就是即写即编译,并且可以指定编译后的css的目录. 本文使用的webstorm为8.0版本 scss安装:http://www.w3cplus.com/sas ...