300个最大质因数小于2000的数,选若干个它们的乘积为完全平方数有多少种方案。

合法方案的每个数的质因数的个数的奇偶值异或起来为0。

比如12=2^2*3,对应的奇偶值为01(2的个数是偶数为0,3的个数是奇数为1),3的对应奇偶值为01,于是12*3是完全平方数。

然后异或方程组就是:

a11x1+a12x2+...+a1nxn=0

a21x1+a22x2+...+a2nxn=0

...

an1x1+an2x2+...+annxn=0

aij:第i个质数(2000内有303个质数)在第j个数里是奇数个则为1,否则为0。

xi:第i个数(最多300个数)被选则为1,否则为0。

求出有多少种解即可。(异或方程组高斯消元求秩,然后解就有2^(n-rank)种,减去全为0的解)

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
#define mod 1000000007
using namespace std;
const int N=;
const int M=;
int prime[N+],cnt;
int n,t,mat[M][M],two[M]={};
ll a[M];
void getPrime(){
for(int i=;i<=N;i++){
if(!prime[i])prime[++cnt]=i;
for(int j=;j<=cnt&&prime[j]<=N/i;j++){
prime[prime[j]*i]=;
if(i%prime[j]==)break;
}
}
}
int Rank(int c[][M]){//异或版的高斯消元求秩
int i=,j=,k,r,u;
while(i<=cnt&&j<=n){
r=i;
while(c[r][j]==&&r<=cnt)r++;
if(c[r][j]){
swap(c[i],c[r]);
for(u=i+;u<=cnt;u++)if(c[u][j])
for(k=i;k<=n;k++)c[u][k]^=c[i][k];
i++;
}
j++;
}
return i;
}
int solve(){
memset(mat,,sizeof mat);
for(int i=;i<=n;i++)
for(int j=;j<=cnt;j++){
ll tmp=a[i];
while(tmp%prime[j]==){
tmp/=prime[j];
mat[j][i]^=;
}
}
int b=n-Rank(mat);//b个自由元
return two[b]-;//减去全为0的解
}
int main() {
getPrime();
for(int i=;i<M;i++)two[i]=two[i-]*%mod;
scanf("%d",&t);
for(int cas=;cas<=t;cas++){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lld",&a[i]);
printf("Case #%d:\n%d\n",cas,solve());
}
return ;
}

  原来是白书上的题(160页)I good vagetable a!

【HDU 5833】Zhu and 772002(异或方程组高斯消元)的更多相关文章

  1. hdu 5833 Zhu and 772002 异或方程组高斯消元

    ccpc网赛卡住的一道题 蓝书上的原题 但是当时没看过蓝书 今天又找出来看看 其实也不是特别懂 但比以前是了解了一点了 主要还是要想到构造异或方程组 异或方程组的消元只需要xor就好搞了 数学真的是硬 ...

  2. 【HDU 5833】Zhu and 772002(异或方程组高斯消元讲解)

    题目大意:给出n个数字a[],将a[]分解为质因子(保证分解所得的质因子不大于2000),任选一个或多个质因子,使其乘积为完全平方数.求其方法数. 学长学姐们比赛时做的,当时我一脸懵逼的不会搞……所以 ...

  3. 3364 Lanterns (异或方程组高斯消元)

    基本思路.首先构造一个n*(m+1)的矩阵,同时标记一个行数row,row从零开始,然后找出每一列第一个非零的数,和第row行互换, 然后对row到n行,异或运算.最终的结果为2^(m-row) #i ...

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

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

  5. HDU 5833 Zhu and 772002

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

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

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

  7. hdu 5833 Zhu and 772002 高斯消元

    Zhu and 772002 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test ...

  8. HDU 2262 Where is the canteen 期望dp+高斯消元

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2262 Where is the canteen Time Limit: 10000/5000 MS ...

  9. 【HDU 3949】 XOR (线性基,高斯消元)

    XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. android ndk 无法找到 so 案例一例

    代码如下: public class JNIWrapWorkerThread{    static {        System.loadLibrary("libjni_base_fram ...

  2. memcache分布式 [一致性hash算法] 的php实现

    最近在看一些分布式方面的文章,所以就用php实现一致性hash来练练手,以前一般用的是最原始的hash取模做分布式,当生产过程中添加或删除一台memcache都会造成数据的全部失效,一致性hash就是 ...

  3. MySQL数据库的优化(上)单机MySQL数据库的优化

    MySQL数据库的优化(上)单机MySQL数据库的优化 2011-03-08 08:49 抚琴煮酒 51CTO 字号:T | T 公司网站访问量越来越大,导致MySQL的压力越来越大,让我们自然想到的 ...

  4. 上传Text文档并转换为PDF(解决乱码)

    前些日子,Insus.NET有分享一篇<上传Text文档并转换为PDF>http://www.cnblogs.com/insus/p/4313092.html 它是按最简单与默认方式来处理 ...

  5. iOS APNS配置(转)

    Introduction To send Push notification to an application/device couple you need an unique device tok ...

  6. 简单谈谈dom解析xml和html

    前言 文件对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口.html,xml都是基于这个模型构造的.这也是一个W3C推出的标准.j ...

  7. 【跟着子迟品underscore】从用 `void 0` 代替 `undefined` 说起

    Why underscore 最近开始看 underscore源码,并将 underscore源码解读 放在了我的 2016计划 中. 阅读一些著名框架类库的源码,就好像和一个个大师对话,你会学到很多 ...

  8. 7z压缩文件时排除指定的文件

    分享一个7z压缩文件时排除指定文件类型的命令行,感觉很有用: 7z a -t7z d:\updateCRM.7z d:\updateCRM\*.* -r -x!*.log -x!*bak a:创建压缩 ...

  9. Log4net使用(二)

    日志记录到根目录Log文件夹,文件夹中分LogError与LogInfo文件夹 web.config配置: <configSections> <section name=" ...

  10. nios II--实验4——按键中断硬件部分

    按键中断 硬件开发 新建原理图 1.打开Quartus II 11.0,新建一个工程,File -> New Project Wizard…,忽略Introduction,之间单击 Next&g ...