SGU 200 Cracking RSA (高斯消元)
转载请注明出处,谢谢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 (高斯消元)的更多相关文章
- SGU 200. Cracking RSA(高斯消元+高精度)
标题效果:鉴于m整数,之前存在的所有因素t素数.问:有多少子集.他们的产品是数量的平方. 解题思路: 全然平方数就是要求每一个质因子的指数是偶数次. 对每一个质因子建立一个方程. 变成模2的线性方程组 ...
- SGU 200.Cracking RSA(高斯消元)
时间限制:0.25s 空间限制:4M 题意: 给出了m(<100)个数,这m个数的质因子都是前t(<100)个质数构成的. 问有多少个这m个数的子集,使得他们的乘积是完全平方数. Solu ...
- Acdream1217 Cracking' RSA(高斯消元)
题意:给你m个数(m<=100),每个数的素因子仅来自于前t(t<=100)个素数,问这m个数的非空子集里,满足子集里的数的积为完全平方数的有多少个. 一开始就想进去里典型的dp世界观里, ...
- SGU 200. Cracking RSA (高斯消元求自由变元个数)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=200 200. Cracking RSA time limit per test: ...
- SGU 260.Puzzle (异或高斯消元)
题意: 有n(<200)个格子,只有黑白两种颜色.可以通过操作一个格子改变它和其它一些格子的颜色.给出改变的关系和n个格子的初始颜色,输出一种操作方案使所有格子的颜色相同. Solution: ...
- ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...
- 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 ...
- SGU 275 To xor or not to xor (高斯消元)
题目链接 题意:有n个数,范围是[0, 10^18],n最大为100,找出若干个数使它们异或的值最大并输出这个最大值. 分析: 一道高斯消元的好题/ 我们把每个数用二进制表示,要使得最后的异或值最大, ...
- SGU 275 To xor or not to xor(高斯消元)
题意: 从n个数中选若干个数,使它们的异或和最大.n<=100 Solution 经典的异或高斯消元. //O(60*n) #include <iostream> using nam ...
随机推荐
- javascript自定义日期函数
1.格式化日期(YYYY-MM-DD) 代码: var DateFormat = function (date) { if (!(date instanceof Date)) { date = dat ...
- 不可综合的verilog语句分析
前半部分转自http://www.cnblogs.com/Mrseven/articles/2247657.html,后半部分为自己测试结果. 基础知识:verilog 不可综合语句 (1)所有综合工 ...
- Asp.net MVC学习--默认程序结构、工作流程
二.MVC 默认程序结构 MVC新建好之后,会对应的出现几个包,分别是:Controller.Model.View --即MVC 其中的默认的Default.aspx文件可以方便url重写,如果不设置 ...
- 收藏的技术文章链接(ubuntu,python,android等)
我的收藏 他山之石,可以攻玉 转载请注明出处:https://ahangchen.gitbooks.io/windy-afternoon/content/ 开发过程中收藏在Chrome书签栏里的技术文 ...
- discuz函数quote
public static function quote($str, $noarray = false) { if (is_string($str)) return '\'' . addcslashe ...
- 字符串比较必须使用strcmp
char s1[]="this" char *s2 = "this" if(s1=="this"){ printf("s1 is ...
- openNebula 运维系列虚拟机virtual machines operations
1,virtual machine manage,VMInstance state; http://docs.opennebula.org/4.4/user/virtual_resource_mana ...
- Emotional Mastery——英语学习小技巧之一
How can we control or manage our emotion ,so that we feel better and feel stronger when we're learni ...
- python IOError: invalid mode ('r') or filename
我想要用pandas.read_table()将数据表中的数据读到一个pandas DataFrame对象中: import pandas as pd unames = ['user_id', 'ge ...
- python 正则表达式 学习笔记(不断补充ing)
本文参考了以下博客,感谢众位大神的分享! http://www.oschina.net/question/12_9507 和 http://www.crifan.com/python_re_sub_d ...