hdu 5833 Zhu and 772002 ccpc网络赛 高斯消元法
题意:给n个数,每个数的素数因子不大于2000,让你从其中选则大于等于1个数相乘之后的结果为完全平方数
思路:
- 小于等于2000的素数一共也只有305个
- 一个数,如果他某个素数因子的幂为偶,那这个素数的可以不用考虑;如果幂为奇数,那这个素数就应当被考虑如何与其他数凑成幂为偶数。例如12,可以表示为2^2*3,2的幂次为2,3的幂次为1,所以,如果要和其他数相乘为完全平方数,那么一定要与素数因子3为奇次的合并
- 那么根据上面两条,我们可以列出方程:x1*a11+x2*a12+...+xn*a1n=0;x为解,如果aii取为1,不取为0;aii表示ai的第i个素数因子是否为奇,是为1,否则为0,(素数按从小到大排序,依次为2,3,5,7...)
- 答案即为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网络赛 高斯消元法的更多相关文章
- 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 5833 Zhu and 772002 异或方程组高斯消元
ccpc网赛卡住的一道题 蓝书上的原题 但是当时没看过蓝书 今天又找出来看看 其实也不是特别懂 但比以前是了解了一点了 主要还是要想到构造异或方程组 异或方程组的消元只需要xor就好搞了 数学真的是硬 ...
- hdu 6152 : Friend-Graph (2017 CCPC网络赛 1003)
题目链接 裸的结论题.百度 Ramsey定理.刚学过之后以为在哪也不会用到23333333333,没想到今天网络赛居然出了.顺利在题面更改前A掉~~~(我觉得要不是我开机慢+编译慢+中间暂时死机,我还 ...
- HDU 5833 Zhu and 772002(高斯消元)
题意:给n个数,从n个数中抽取x(x>=1)个数,这x个数相乘为完全平方数,求一共有多少种取法,结果模1000000007. 思路:每个数可以拆成素数相乘的形式,例如: x1 2=2^1 * 3 ...
- HDU 5833 Zhu and 772002 (数论+高斯消元)
题目链接 题意:给定n个数,这n个数的素因子值不超过2000,从中取任意个数使其乘积为完全平方数,问有多少种取法. 题解:开始用素筛枚举写了半天TLE了,后来队友说高斯消元才想起来,果断用模板.赛后又 ...
- HDU - 5833: Zhu and 772002 (高斯消元-自由元)
pro:给定N个数Xi(Xi<1e18),保证每个数的素因子小于2e3:问有多少种方案,选处一些数,使得数的乘积是完全平方数.求答案%1e9+7: N<300; sol:小于2e3的素数只 ...
- HDU 5833 Zhu and 772002 ——线性基
[题目分析] 这题貌似在UVA上做过,高精度高斯消元. 练习赛T2,然后突然脑洞出来一个用Bitset的方法. 发现代码只需要30多行就A掉了 Bitset大法好 [代码] #include < ...
随机推荐
- mongodb安装与使用
一.在linux服务器中安装mongodb 1.首先你要有一台安装有linux系统的主机 2.从mongoDB官网下载安装包:http://www.mongodb.org/downloads 3.将下 ...
- nginx配合modsecurity实现WAF功能
一.准备工作 系统:centos 7.2 64位.nginx1.10.2, modsecurity2.9.1 owasp3.0 1.nginx:http://nginx.org/download/ng ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q35-Q39)
Question 35You have a custom Web Part that is deployed as a sandboxed solution.You need to ensure th ...
- android AsyncTask 只能在线程池里单个运行的问题
android 的AysncTask直接调用Execute会在在一个线程池里按调用的先后顺序依次执行. 如果应用的所有网络获取都依赖这个来做,当有一个网络请求柱塞,就导致其它请求也柱塞了. 在3.0 ...
- Android项目实战(十二):解决OOM的一种偷懒又有效的办法
在程序的manifest文件的application节点加入android:largeHeap=“true” 即可. 对,只需要一句话! 那么这行代码的意思是什么呢? 简单的说就是使该APP获取最大可 ...
- Android文件操作
将数据写入Internal Storage: String fileName = "myfile.txt"; String str="保存数据到内部存储"; t ...
- Gnome排序算法
Gnome排序(地精排序),起初由Hamid Sarbazi-Azad 于2000年提出,并被称为stupid排序,后来被Dick Grune描述并命名为“地精排序”,作为一个排序算法,和插入排序类似 ...
- CoreAnimation(CA)
开发者真会玩,原来我看到CA都懵了.啥是CA?原来就是Core Animation.哎,读书少啊,被虐成
- iOS打印Debug日志的方式
简单介绍以下几个宏: 1) __VA_ARGS__ 是一个可变参数的宏,这个可变参数的宏是新的C99规范中新增的,目前似乎只有gcc支持(VC6.0的编译器不支持).宏前面加上##的作用在于,当可变参 ...
- HTML5 拖放
拖放(Drag 和 drop)是 HTML5 标准的组成部分. 拖放 拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放. 浏览器支持 I ...