传送门:hdu 5833 Zhu and 772002

题意:给n个数,每个数的素数因子不大于2000,让你从其中选则大于等于1个数相乘之后的结果为完全平方数

思路:

  1. 小于等于2000的素数一共也只有305个
  2. 一个数,如果他某个素数因子的幂为偶,那这个素数的可以不用考虑;如果幂为奇数,那这个素数就应当被考虑如何与其他数凑成幂为偶数。例如12,可以表示为2^2*3,2的幂次为2,3的幂次为1,所以,如果要和其他数相乘为完全平方数,那么一定要与素数因子3为奇次的合并
  3. 那么根据上面两条,我们可以列出方程:x1*a11+x2*a12+...+xn*a1n=0;x为解,如果aii取为1,不取为0;aii表示ai的第i个素数因子是否为奇,是为1,否则为0,(素数按从小到大排序,依次为2,3,5,7...)
  4. 答案即为2^(x中自由元的个数)-1
/**************************************************************
Problem:hdu 5833 Zhu and 772002
User: youmi
Language: C++
Result: Accepted
Time:
Memory:
****************************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#define zeros(a) memset(a,0,sizeof(a))
#define ones(a) memset(a,-1,sizeof(a))
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scs(a) scanf("%s",a)
#define sclld(a) scanf("%I64d",&a)
#define pt(a) printf("%d\n",a)
#define ptlld(a) printf("%I64d\n",a)
#define rep(i,from,to) for(int i=from;i<=to;i++)
#define irep(i,to,from) for(int i=to;i>=from;i--)
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define lson (step<<1)
#define rson (lson+1)
#define eps 1e-6
#define oo 0x3fffffff
#define TEST cout<<"*************************"<<endl
const double pi=*atan(1.0); using namespace std;
typedef long long ll;
template <class T> inline void read(T &n)
{
char c; int flag = ;
for (c = getchar(); !(c >= '' && c <= '' || c == '-'); c = getchar()); if (c == '-') flag = -, n = ; else n = c - '';
for (c = getchar(); c >= '' && c <= ''; c = getchar()) n = n * + c - ''; n *= flag;
}
ll Pow(ll base, ll n, ll mo)
{
if (n == ) return ;
if (n == ) return base % mo;
ll tmp = Pow(base, n >> , mo);
tmp = (ll)tmp * tmp % mo;
if (n & ) tmp = (ll)tmp * base % mo;
return tmp;
}
//*************************** int n;
const ll mod=;
const int maxn=;
ll prime[maxn];
bool isprime[maxn*];
int tot;
int a[][];
int x[];
int fre[];
int index;
int tt=;
void prim()//素数筛法
{
tot=;
memset(isprime,true,sizeof(isprime));
prime[tot++]=;
for(int i=;i<maxn;i+=)
{
if(isprime[i])
{
prime[tot++]=i;
for(ll j=i;1ll*i*j<1ll*maxn;j+=)
isprime[i*j]=false;
}
}
}
void solve(int i,ll x)//判断x有哪些素数因子的幂为奇
{
int cnt=;
rep(j,,tot)
{
cnt=;
if(x%prime[j]==)
{
while(x%prime[j]==)
{
cnt++;
x/=prime[j];
}
}
if(cnt%)
a[i][j]=;
if(x==)
break;
}
}
void debug(int rw,int cl)
{
rep(i,,rw-)
{
rep(j,,cl-)
printf("%d ",a[i][j]);
printf("\n");
}
}
int gauss(int rw,int cl)//高斯消元法,01异或
{
int i,j,k;
int mx=;
for(i=,j=;i<rw&&j<cl-;i++,j++)
{
mx=i;
for(k=i;k<rw;k++)
{
if(abs(a[k][j])>abs(a[mx][j]))
mx=k;
}
if(mx!=i)
{
for(k=j;k<cl;k++)
swap(a[mx][k],a[i][k]);
}
if(a[i][j]==)
{
i--;
continue;
}
for(k=i+;k<rw;k++)
{
if(a[k][j]!=)
{
for(int t=j;t<cl;t++)
{
a[k][t]^=a[i][t];
}
}
}
}
if(i<rw)
{
for(k=i-;k>=;k--)
{
int num=;
for(int t=;t<cl;t++)
{
if(a[k][t]!=&&fre[t])
num++,index=t;
}
if(num>)
continue;
int temp=a[k][cl-];
for(int t=;t<cl-;t++)
if(a[k][t]!=&&index!=t)
temp^=a[k][t]&&x[t];
x[k]=temp&&a[k][k];
fre[index]=;
}
return rw-i;
}
return ;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
prim();
int T;
scanf("%d", &T);
for (int kase = ;kase <= T;kase++)
{
int n;
scanf("%d", &n);
zeros(a);
zeros(x);
memset(fre,,sizeof(fre));
for (int i=;i<n;i++)
{
long long x;
scanf("%I64d", &x);
solve(i,x);
}
ll ans=gauss(n,tt);
ans=(Pow(,ans,mod)-+mod)%mod;
printf("Case #%d:\n%I64d\n", kase,ans);
}
return ;
}

hdu 5833 Zhu and 772002 ccpc网络赛 高斯消元法的更多相关文章

  1. HDU 5833 Zhu and 772002

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

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

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

  3. hdu 5833 Zhu and 772002 高斯消元

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

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

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

  5. hdu 6152 : Friend-Graph (2017 CCPC网络赛 1003)

    题目链接 裸的结论题.百度 Ramsey定理.刚学过之后以为在哪也不会用到23333333333,没想到今天网络赛居然出了.顺利在题面更改前A掉~~~(我觉得要不是我开机慢+编译慢+中间暂时死机,我还 ...

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

    题意:给n个数,从n个数中抽取x(x>=1)个数,这x个数相乘为完全平方数,求一共有多少种取法,结果模1000000007. 思路:每个数可以拆成素数相乘的形式,例如: x1 2=2^1 * 3 ...

  7. HDU 5833 Zhu and 772002 (数论+高斯消元)

    题目链接 题意:给定n个数,这n个数的素因子值不超过2000,从中取任意个数使其乘积为完全平方数,问有多少种取法. 题解:开始用素筛枚举写了半天TLE了,后来队友说高斯消元才想起来,果断用模板.赛后又 ...

  8. HDU - 5833: Zhu and 772002 (高斯消元-自由元)

    pro:给定N个数Xi(Xi<1e18),保证每个数的素因子小于2e3:问有多少种方案,选处一些数,使得数的乘积是完全平方数.求答案%1e9+7: N<300; sol:小于2e3的素数只 ...

  9. HDU 5833 Zhu and 772002 ——线性基

    [题目分析] 这题貌似在UVA上做过,高精度高斯消元. 练习赛T2,然后突然脑洞出来一个用Bitset的方法. 发现代码只需要30多行就A掉了 Bitset大法好 [代码] #include < ...

随机推荐

  1. 使用PreparedStatement执行SQL语句时占位符(?)的用法

    1.Student数据库表 ID  name gender       2.Java代码 public static void main(String[] args) { int _id=1; Str ...

  2. xshell下载文件到本地/上传文件到服务器

    xshell很好用,然后有时候想在windows和linux上传或下载某个文件,其实有个很简单的方法就是rz,sz首先你的Ubuntu需要安装rz.sz(如果没有安装请执行以下命令,安装完的请跳过.其 ...

  3. jQuery中的事件冒泡

    1.什么是冒泡 eg: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <he ...

  4. CentOS6.5 FTP配置

    一:安装vsftpd 查看是否已经安装vsftpd rpm -qa | grep vsftpd 如果没有,就安装,并设置开机启动 yum -y install vsftpd chkconfig vsf ...

  5. ASP.NET WebAPI 09 Controller的激活

    在Controller之前我们先回顾一下HttpMessageHandler通道. 在这个图中我留一个HttpContollerDispatcher没有说明.因为这个类也是继承自HttpMessage ...

  6. bootstrap dialog自行控制窗口的关闭

    在使用dialog的时候,我们通常不希望点击btn的时候自动隐藏dialog,通常需要做一些清理或者ajax操作,在bootstrap dialog中,这是通过 data-dismiss=" ...

  7. JVM的ClassLoader过程分析

    本文来自网络:深入分析Java ClassLoader原理 http://my.oschina.net/zhengjian/blog/133836 一. JVM的ClassLoader过程以及装载原理 ...

  8. js中的浅拷贝和深拷贝

    说说最近所学:浅拷贝和深拷贝也叫做浅克隆和深克隆,深浅主要针对的是对象的"深度",常见的对象都是"浅"的,也就是对象里的属性就是单个的属性,而"深&q ...

  9. Atitit. Atiposter 发帖机 新特性 poster new feature   v7 q39

    Atitit. Atiposter 发帖机 新特性 poster new feature   v7 q39 V1  初步实现sina csdn cnblogs V2  实现qzone sohu 的发帖 ...

  10. [ javascript html Dom image 对象事件加载方式 ] 对象事件加载方式

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...