题目链接:点击打开链接

白书的例题练练手。

P161

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define ll int
#define LL long long
const int mod = 1000000009;
const int maxn = 510;
const int maxp = 100;
ll prime[1000],primenum;//有primenum个素数 math.h
void PRIME(ll Max_Prime){
primenum=0;
prime[primenum++]=2;
for(ll i=3;i<=Max_Prime;i+=2)
for(ll j=0;j<primenum;j++)
if(i%prime[j]==0)break;
else if(prime[j]>sqrt((double)i) || j==primenum-1)
{
prime[primenum++]=i;
break;
}
} typedef int Matrix[maxn][maxn]; int rank(Matrix A, int m, int n) { //m个方程n个变量
int i = 0, j = 0, k, r, u;
while(i < m && j < n)
{
r = i;
for(k = i; k < m; k++)
if(A[k][j])
{ r = k; break; }
if(A[r][j])
{
if(r != i)
for(k = 0; k <= n; k++) swap(A[r][k], A[i][k]);
for(u = i+1; u < m; u++) if(A[u][j])
for(k = i; k <= n; k++) A[u][k] ^= A[i][k];
i++;
}
j++;
}
return i;
} Matrix A; int main(){
PRIME(500);
int T; cin>>T;
while(T--) {
int n, maxp = 0;
long long x;
cin>> n;
memset(A, 0, sizeof A);
for(int i = 0; i < n; i++)
{
cin>> x;
for(int j = 0; j < primenum; j++)
while(x % prime[j] == 0)
{
maxp = max(maxp, j);
x /= prime[j];
A[j][i] ^= 1;
}
}
int r = rank(A, maxp+1, n);
cout<< (1LL << (n-r))-1 <<endl;
}
return 0;
}

UVA 11542 Square 高斯消元 异或方程组求解的更多相关文章

  1. UVA 11542 - Square(高斯消元)

    UVA 11542 - Square 题目链接 题意:给定一些数字.保证这些数字质因子不会超过500,求这些数字中选出几个,乘积为全然平方数,问有几种选法 思路:对每一个数字分解成质因子后.发现假设要 ...

  2. UVa 11542 Square (高斯消元)

    题意:给定 n 个数,从中选出一个,或者是多个,使得选出的整数的乘积是完全平方数,求一共有多少种选法,整数的素因子不大于 500. 析:从题目素因子不超过 500,就知道要把每个数进行分解.因为结果要 ...

  3. UVA11542 Square(高斯消元 异或方程组)

    建立方程组消元,结果为2 ^(自由变元的个数) - 1 采用高斯消元求矩阵的秩 方法一: #include<cstdio> #include<iostream> #includ ...

  4. BZOJ.1923.[SDOI2010]外星千足虫(高斯消元 异或方程组 bitset)

    题目链接 m个方程,n个未知量,求解异或方程组. 复杂度比较高,需要借助bitset压位. 感觉自己以前写的(异或)高斯消元是假的..而且黄学长的写法都不需要回代. //1100kb 324ms #i ...

  5. Tsinsen-A1488 : 魔法波【高斯消元+异或方程组】

    高斯消元. 自己只能想出来把每一个点看成一个变量,用Xi表示其状态,这样必定TLE,n^2 个变量,再加上3次方的高斯消元(当然,可以用bitset压位). 正解如下: 我们把地图划分成一个个的横条和 ...

  6. UVa 11542 (高斯消元 异或方程组) Square

    书上分析的太清楚,我都懒得写题解了.=_=|| #include <cstdio> #include <cstring> #include <cmath> #inc ...

  7. POJ.1830.开关问题(高斯消元 异或方程组)

    题目链接 显然我们需要使每个i满足\[( ∑_{j} X[j]*A[i][j] ) mod\ 2 = B[i]\] 求这个方程自由元Xi的个数ans,那么方案数便是\(2^{ans}\) %2可以用^ ...

  8. 【高斯消元解xor方程组】BZOJ2466-[中山市选2009]树

    [题目大意] 给出一棵树,初始状态均为0,每反转一个节点的状态,相邻的节点(父亲或儿子)也会反转,问要使状态均为1,至少操作几次? [思路] 一场大暴雨即将来临,白昼恍如黑夜!happy! 和POJ1 ...

  9. poj1830(高斯消元解mod2方程组)

    题目链接:http://poj.org/problem?id=1830 题意:中文题诶- 思路:高斯消元解 mod2 方程组 有 n 个变元,根据给出的条件列 n 个方程组,初始状态和终止状态不同的位 ...

随机推荐

  1. ffmpeg实现

    最近做一个小项目,要在线播放录制的 MP4 视频,想开源的 flash player 或 html 5 可以播放.可,虽然 MP4 是 H.264 编码,但就是播放不了.可能是封装方式(PS 方式)不 ...

  2. POJ 3275 Floyd传递闭包

    题意:Farmer John想按照奶牛产奶的能力给她们排序.现在已知有N头奶牛(1 ≤ N ≤ 1,000).FJ通过比较,已经知道了M(1 ≤ M ≤ 10,000)对相对关系.每一对关系表示为&q ...

  3. C - Oleg and shares

    Problem description Oleg the bank client checks share prices every day. There are n share prices he ...

  4. (转载) 小议TCP的MSS(最大分段)以及MTU(最大传输单元)

    [背景知识]  MTU: Maximum Transmission Unit 最大传输单元 MSS: Maximum Segment Size 最大分段大小PPPoE: PPP Over Ethern ...

  5. Android Material Design之CollapsingToolbarLayout使用

    CollapsingToolbarLayout作用是提供了一个可以折叠的Toolbar,它继承至FrameLayout,给它设置layout_scrollFlags,它可以控制包含在Collapsin ...

  6. 关于生sql中的空值

    在数据库中的空值无非就是两种形式的表示 一种是什么都没有,一种是以NuLL显示的 , 那么在C# 读取出来怎么判断呢, DtStatus.Rows[0]["FetchCode"]. ...

  7. Redhat/CentOS xfs文件系统及磁盘挂载

    #!/bin/sh #DEVICE_LIST=""DEVICE_LIST="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /d ...

  8. VHDL之package

    Pacakge Frequently used pieces of VHDL code are usually written in the form of COMPONENTS, FUNCTIONS ...

  9. 杭电 1040 As Easy As A+B 【排序】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1040 解题思路:数据不大,可以直接用冒泡排序 #include<stdio.h> int ...

  10. (转)基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览

    http://www.cnblogs.com/wuhuacong/p/3871991.html 基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览 在博客园很多文章 ...