转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove

题意:给出m个整理,因子全部为前t个素数。问有多少个子集,乘积是平方数

http://acm.sgu.ru/problem.php?contest=0&problem=200

做法:列方程组,a1,a2,a3……am分别表示bi是否在集合中。对于每一个素因子,建立异或方程组,要求因子个数为偶数,即异或为0。

子集个数便是解的个数,高斯消元后求出变元个数num,结果是2^ num-1。除去空集。。

还要模拟一下高精度

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
using namespace std;
const int N = 100;
int t,m;
int b[N];
int a[N][N+1]={0};
int prime[N],flag[N*11]={0},cnt=0;
void Init(){
for(int i=2;i<=1000;i++){
if(flag[i]) continue;
prime[cnt++]=i;
if(cnt==t) return ;
for(int j=2;j*i<=1000;j++)
flag[i*j]=1;
}
}
int gauss(int n,int m){
int i,j;
for(i=0,j=0;i<n&&j<m;j++){
int k;
for(k=i;k<n;k++)
if(a[k][j])
break;
if(k<n){
for(int r=j;r<=m;r++)
swap(a[i][r],a[k][r]);
for(int r=0;r<n;r++){
if(r!=i&&a[r][j]){
for(int t=j;t<=m;t++)
a[r][t]^=a[i][t];
}
}
i++;
}
}
return m-i;
}
int ans[N];
void out(){
for(int i=ans[0];i>=1;i--)
printf("%d",ans[i]);
if(ans[0]==0) printf("0");
printf("\n");
}
void gao(){
for(int i=1;i<=ans[0];i++){
ans[i]*=2;
}
for(int p=1;p<=ans[0];p++){
if(ans[p]>=10){
ans[p]%=10;
ans[p+1]++;
}
}
if(ans[ans[0]+1]>0) ans[0]++;
}
void fuck(){
ans[1]--;
int p=1;
while(ans[p]<0){
ans[p]+=10;
ans[++p]--;
}
if(ans[ans[0]]==0) ans[0]--;
}
int main(){
scanf("%d%d",&t,&m);
Init();
for(int i=0;i<m;i++){
scanf("%d",&b[i]);
for(int j=0;j<t;j++){
while(b[i]%prime[j]==0){
a[j][i]^=1;
b[i]/=prime[j];
}
}
}
int p=gauss(t,m);
ans[0]=ans[1]=1;
for(int i=1;i<=p;i++)
gao();
fuck();
out();
return 0;
}

SGU 200 Cracking RSA (高斯消元)的更多相关文章

  1. SGU 200. Cracking RSA(高斯消元+高精度)

    标题效果:鉴于m整数,之前存在的所有因素t素数.问:有多少子集.他们的产品是数量的平方. 解题思路: 全然平方数就是要求每一个质因子的指数是偶数次. 对每一个质因子建立一个方程. 变成模2的线性方程组 ...

  2. SGU 200.Cracking RSA(高斯消元)

    时间限制:0.25s 空间限制:4M 题意: 给出了m(<100)个数,这m个数的质因子都是前t(<100)个质数构成的. 问有多少个这m个数的子集,使得他们的乘积是完全平方数. Solu ...

  3. Acdream1217 Cracking' RSA(高斯消元)

    题意:给你m个数(m<=100),每个数的素因子仅来自于前t(t<=100)个素数,问这m个数的非空子集里,满足子集里的数的积为完全平方数的有多少个. 一开始就想进去里典型的dp世界观里, ...

  4. SGU 200. Cracking RSA (高斯消元求自由变元个数)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=200 200. Cracking RSA time limit per test: ...

  5. SGU 260.Puzzle (异或高斯消元)

    题意: 有n(<200)个格子,只有黑白两种颜色.可以通过操作一个格子改变它和其它一些格子的颜色.给出改变的关系和n个格子的初始颜色,输出一种操作方案使所有格子的颜色相同. Solution: ...

  6. ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...

  7. SGU 275 To xor or not to xor 高斯消元求N个数中选择任意数XORmax

    275. To xor or not to xor   The sequence of non-negative integers A1, A2, ..., AN is given. You are ...

  8. SGU 275 To xor or not to xor (高斯消元)

    题目链接 题意:有n个数,范围是[0, 10^18],n最大为100,找出若干个数使它们异或的值最大并输出这个最大值. 分析: 一道高斯消元的好题/ 我们把每个数用二进制表示,要使得最后的异或值最大, ...

  9. SGU 275 To xor or not to xor(高斯消元)

    题意: 从n个数中选若干个数,使它们的异或和最大.n<=100 Solution 经典的异或高斯消元. //O(60*n) #include <iostream> using nam ...

随机推荐

  1. js关闭 window.open 打开的页面

    1.关闭 当前页面 window.opener = null; window.open('', '_self', ''); window.close(); 但是在FF中就是不行: 2.项目中情况是通过 ...

  2. 【Chromium中文文档】多进程资源加载

    多进程资源加载(需要更新) 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture ...

  3. Codeforces 263E

    Codeforces 263E 原题 题目描述:一个\(n \times m\)的矩阵,每格有一个数,给出一个整数\(k\),定义函数\(f(x, y)\): \[f(x, y)=\sum_{i=1} ...

  4. poj1543---完美立方(枚举)

    #include <stdio.h> #include <stdlib.h> int main() { int cube[101],n,i,a,b,c,d; for(i=1;i ...

  5. New Relic——手机应用app开发达人的福利立即就到啦!

    HiWork集成的第三方服务(机器人)将有新的添加啦,添加了BitBucket和New Relic.分别做下介绍啦! 1.BitBucket BitBucket 是一家源码托管站点.採用Mercuri ...

  6. 关于bootstrap弹出二级对话框的使用

    弹出二级对话框,即在对话框的基础上再弹出一个对话框.这对于CRM管理类系统来说应用场景很常见.看到网上有关于实现二级弹出框的方法,需要在一级对话框页面上添加不少css样式.其实,完全可以不用这么麻烦. ...

  7. 2014.8.20break,continue,字符串,数字和日期

    (一)break与continue break——彻底终断循环 continue——中断本次循环,继续下次循环 break举例: //求100以内所有质数 ; i <= ; i++) { ;// ...

  8. JavaSE复习日记 : 抽象类

    /* * 抽象类 * 抽象: * 面向对象的三大核心思想; * 封装: 封装,ppp是封装的一部分 * 继承; * 多态: 父类的引用指向子类的对象 * 引用: 是指一个引用型变量 * 有哪些变量? ...

  9. math。h中的log函数的应用

    以10为底的log函数: 形式为 double  log10(double  x) 以e为底的log函数(即 ln)double log (double x) 如何表达log 以a为底b的对数: 用换 ...

  10. ROS中编辑文件命令行工具rosed

    rosed是rosbash套件中的一个,它允许我们通过包名直接编辑包中的文件,而不是输入包的全部路径. 用法: rosed [package_name] [filename] 例如: rosed ro ...