参考自:http://www.cnblogs.com/flipped/p/5771492.html

自己做的时候不知道如何求种数。看了题解,感觉思路灰常巧妙。同时也感觉这是一道好题。

精髓在于转化为线性方程组。

求素数的思想,和高斯消元需要多加熟悉。

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<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define LL long long
#define mod 1000000007 const int N=;
const int M=; int prime[N+],cnt;
int n,t,mat[M][M];
LL a[M]; void getPrime() //求2000以内的所有质数
{
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);
LL ans=,k=;
while(b) //快速幂
{
if(b&)
ans=ans*k%mod;
k=k*k%mod;
b>>=;
}
return ans-;
} int main()
{
int cas=;
getPrime(); scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%I64d",&a[i]);//cout<<"*";
printf("Case #%d:\n%d\n",cas++,solve());
}
}

HDU_5833_高斯消元的更多相关文章

  1. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  2. 【BZOJ-3270】博物馆 高斯消元 + 概率期望

    3270: 博物馆 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 292  Solved: 158[Submit][Status][Discuss] ...

  3. *POJ 1222 高斯消元

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9612   Accepted: 62 ...

  4. [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...

  5. hihoCoder 1196 高斯消元·二

    Description 一个黑白网格,点一次会改变这个以及与其连通的其他方格的颜色,求最少点击次数使得所有全部变成黑色. Sol 高斯消元解异或方程组. 先建立一个方程组. \(x_i\) 表示这个点 ...

  6. BZOJ 2844 albus就是要第一个出场 ——高斯消元 线性基

    [题目分析] 高斯消元求线性基. 题目本身不难,但是两种维护线性基的方法引起了我的思考. void gauss(){ k=n; F(i,1,n){ F(j,i+1,n) if (a[j]>a[i ...

  7. SPOJ HIGH Highways ——Matrix-Tree定理 高斯消元

    [题目分析] Matrix-Tree定理+高斯消元 求矩阵行列式的值,就可以得到生成树的个数. 至于证明,可以去看Vflea King(炸树狂魔)的博客 [代码] #include <cmath ...

  8. UVALive 7138 The Matrix Revolutions(Matrix-Tree + 高斯消元)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  9. [高斯消元] POJ 2345 Central heating

    Central heating Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 614   Accepted: 286 Des ...

随机推荐

  1. Haybale Guessing

    Haybale Guessing Time Limit: 1000MS   Memory Limit: 65536K       Description The cows, who always ha ...

  2. MINSUB - Largest Submatrix

    MINSUB - Largest Submatrix no tags  You are given an matrix M (consisting of nonnegative integers) a ...

  3. Caused by: android.os.TransactionTooLargeException总结

    错误信息 Error: android.os.TransactionTooLargeException W/ActivityManager(344): android.os.TransactionTo ...

  4. 微信获得access-token

    微信获得access-token RestTemplate template = new RestTemplate(); String appid = "aa"; String s ...

  5. [Angular] Remove divs to Preserve Style and Layout with ng-container in Angular

    The Angular <ng-container> is a grouping element that doesn't interfere with styles or layout ...

  6. eclipse 执行MapReduce程序错误异常汇总(解决Map not fount)

    错误一: Error: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class wordCount.wordCount$ ...

  7. hdu1316(大数的斐波那契数)

    题目信息:求两个大数之间的斐波那契数的个数(C++/JAVA) pid=1316">http://acm.hdu.edu.cn/showproblem.php? pid=1316 这里 ...

  8. Candy [leetcode] O(n)时间复杂度,O(1)空间复杂度的方法

    对于ratings[i+1],和ratings[i]的关系有下面几种: 1. 相等.相等时ratings[i+1]相应的糖果数为1 2.ratings[i + 1] > ratings[i].在 ...

  9. 王立平--Failed to pull selection

    解决的方法:重新启动eclipse

  10. Android Fragment实现button间的切换

    原文地址:http://blog.csdn.net/a123demi/article/details/32693037 Fragment要点 Fragment是activity的界面中的一部分或一种行 ...