hdu 5833 Zhu and 772002 异或方程组高斯消元
ccpc网赛卡住的一道题
蓝书上的原题 但是当时没看过蓝书
今天又找出来看看 其实也不是特别懂 但比以前是了解了一点了
主要还是要想到构造异或方程组 异或方程组的消元只需要xor就好搞了
数学真的是硬伤啊……
(链接:蓝书161页详细讲解 我也在看……
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#define cl(a,b) memset(a,b,sizeof(a))
#define debug(x) cerr<<#x<<"=="<<(x)<<endl
using namespace std;
typedef long long ll; const int maxn=3e2+;
const int maxx=2e3+;
const int mod=1e9+; int n,maxp,tol;
int prime[maxn];
int A[maxn][maxn]; ll powmod(ll a,ll x)
{
ll t=;
while(x)
{
if(x&) t=t*a%mod;
a=a*a%mod;
x>>=;
}
return t;
} void init()
{
bool notprime[maxx];
cl(notprime,false);
notprime[]=notprime[]=true;
for(int i=; i<maxx; i++)
{
if(!notprime[i])
{
if(i*i>maxx) continue;
for(int j=i*i; j<maxx; j+=i)
notprime[j]=true;
}
}
tol=;
for(int i=; i<maxx; i++)
if(!notprime[i]) prime[tol++]=i;
} ll Gauss(int m)
{
int i=,j=,r;
while(j<m&&i<n)
{
r=i;
for(int k=i; k<m; k++)
if(A[k][j]){r=k;break;}
if(A[r][j]){
if(r!=i) for(int k=; k<=n; k++) swap(A[r][k],A[i][k]);
for(int u=i+; u<m; u++) if(A[u][j])
for(int k=i; k<=n; k++) A[u][k]^=A[i][k];
i++;
}
j++;
}
return i;
} int main()
{
int T,cas=;
scanf("%d",&T);
init();
while(T--)
{
int maxp=;
ll x;
scanf("%d",&n);
memset(A,,sizeof(A));
for(int i=; i<n; i++)
{
scanf("%lld",&x);
for(int j=; j<tol; j++)
{
while(x%prime[j]==)
{
maxp=max(maxp,j);
x/=prime[j];
A[j][i]^=;
}
}
}
ll r=Gauss(maxp+);
ll tmp=n-r;
ll ans=powmod(,tmp)-;
printf("Case #%d:\n",cas++);
printf("%lld\n",ans);
}
return ;
} /* 3
4
4 6 10 15
3
3 3 4
3
2 2 2 */
hdu 5833 Zhu and 772002 异或方程组高斯消元的更多相关文章
- 【HDU 5833】Zhu and 772002(异或方程组高斯消元)
300个最大质因数小于2000的数,选若干个它们的乘积为完全平方数有多少种方案. 合法方案的每个数的质因数的个数的奇偶值异或起来为0. 比如12=2^2*3,对应的奇偶值为01(2的个数是偶数为0,3 ...
- 【HDU 5833】Zhu and 772002(异或方程组高斯消元讲解)
题目大意:给出n个数字a[],将a[]分解为质因子(保证分解所得的质因子不大于2000),任选一个或多个质因子,使其乘积为完全平方数.求其方法数. 学长学姐们比赛时做的,当时我一脸懵逼的不会搞……所以 ...
- 3364 Lanterns (异或方程组高斯消元)
基本思路.首先构造一个n*(m+1)的矩阵,同时标记一个行数row,row从零开始,然后找出每一列第一个非零的数,和第row行互换, 然后对row到n行,异或运算.最终的结果为2^(m-row) #i ...
- hdu 5833 Zhu and 772002 ccpc网络赛 高斯消元法
传送门:hdu 5833 Zhu and 772002 题意:给n个数,每个数的素数因子不大于2000,让你从其中选则大于等于1个数相乘之后的结果为完全平方数 思路: 小于等于2000的素数一共也只有 ...
- HDU 5833 Zhu and 772002
HDU 5833 Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- HDU 5833 Zhu and 772002 (高斯消元)
Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...
- hdu 5833 Zhu and 772002 高斯消元
Zhu and 772002 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test ...
- 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 ...
- 【HDU 3949】 XOR (线性基,高斯消元)
XOR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- 凝结时光:ImageMagick 制作 gif
从去年12.12开始,工作日都会从单位的落地窗向外拍一张照片,有点每日打卡的意思.weekday 是一天不落的,weekend 不是每次都到单位,落了几次. 想法来自上学的时候,有同学在同一个地方,拍 ...
- 跨域访问 REST API
跨域访问 Web Service (REST API) 虽然 JQuery 也能通过授权header实现跨域, 但SharePoint 提供了更简单的方法,它被实现在SP.RequestExecuto ...
- iOS基础 - 类扩展
一.类扩展(class extension,匿名分类) 1.格式 @interface 类名 () { // 成员变量... } // 方法声明... @end 2.作用 1> 写在.m文件中 ...
- linux 编程技术
linux 编程技术No.1前期准备工作 GCC的编译过程分为预处理.生成汇编代码.生成目标代码和链接成可执行文件等4个步骤. 使用vim编写C 文件 : [lining@localhost prog ...
- 解决Xcode升级7.0后,部分.a静态库在iOS9.0的模拟器上,link失败的问题
简单描述一下这个问题:我们项目中使用了Google大神开发的LevelDB键值对数据库,在Xcode6,iOS8的环境下,编译好的.a静态库是可以正常使用的.但是升级后,发现在模拟器上无法link成功 ...
- vector cin
vector<int>vec1,vec2; int ival; cout<<"Ender numbers for vector1(-1 to end):"& ...
- pearl(二分查找,stl)
最近大概把有关二分的题目都看了一遍... 嗯..这题是二分查找...二分查找的代码都类似,所以打起来会水很多 但是刚开始打二分还是很容易写挂..所以依旧需要注意 题2 天堂的珍珠 [题目描述] 我有很 ...
- Python多线程的创建,相关函数和守护线程的理解
一:多线程的创建 threading库创建线程有两种方式,函数式和继承式 1)函数式 def func(): print 'Starting' print 'Ending' t=threadin ...
- 图解JS的传值与传址
//编程过程中经常会碰到传值,传址的问题!今天的主题就是关于传值.与传址. //先讲讲赋值操作 //下例是原始类型赋值操作 var a=1,b=a,a=2; console.log("a=& ...
- CSS居中方法搜集
转自这里:http://jinlong.github.io/blog/2013/08/13/centering-all-the-directions/ 兼容低版本IE的方法 html使用表格结构 背景 ...