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. 【leetcode】Integer to Roman

    Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within t ...

  2. nyoj_34_韩信点兵

     中国剩余定理: 代码: #include <iostream> #include <cstdio> using namespace std; int main() { int ...

  3. monitor system

    #!/bin/bash # #Snapshot_Stats - produces a report for system stats # This report will mail to root. ...

  4. ASM:《X86汇编语言-从实模式到保护模式》第13章:保护模式下内核的加载,程序的动态加载和执行

    ★PART1:32位保护模式下内核简易模型 1. 内核的结构,功能和加载 每个内核的主引导程序都会有所不同,因为内核都会有不同的结构.有时候主引导程序的一些段和内核段是可以共用的(事实上加载完内核以后 ...

  5. C Primer Plus_第二章_C语言概述_复习题与编程练习

    REVIEW 1.如何称呼C程序的基本模块? ans 它们被称为函数 2.什么是语法错误?给出一个英语例子和一个C语言例子 me C的语法错误是指把正确的C符号放在了错误的位置 likes codin ...

  6. WP开发资源

    wp开发:连续两次点击返回键退出程序的设计: http://hi.baidu.com/youngytj/item/6be317719cc371306cc37ce4 X http://www.cnblo ...

  7. 把图标改成web字体

    一.下载自己想要的矢量图标,然后在AI中打开二.在AI中将有瑕疵的图标修改一下,再分别另存为svg格式的图标三.打开IcoMoon Web app网页,然后点击左上角的+Import Icons添加你 ...

  8. 【leetcode】Remove Linked List Elements(easy)

    Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...

  9. Linux 添加新硬盘 LVM操作(作用:新增硬盘的卷管理)

    1 查看当前系统硬盘及分区情况 (注:linux中SCSI的第1个硬盘/dev/sda,第2个硬盘/dev/sdb依此类推) 2 初始化分区sdb为物理卷pv pvcreate /dev/sdb  / ...

  10. php date函数 参数详细

    time()在PHP中是得到一个数字,这个数字表示从1970-01-01到现在共走了多少秒,很奇怪吧 不过这样方便计算, 要找出前一天的时间就是 time()-60*60*24; 要找出前一年的时间就 ...