标题效果:鉴于m整数,之前存在的所有因素t素数。问:有多少子集。他们的产品是数量的平方。

解题思路:

全然平方数就是要求每一个质因子的指数是偶数次。

对每一个质因子建立一个方程。

变成模2的线性方程组。

求解这个方程组有多少个自由变元。答案就是 2^p - 1 。(-1是去掉空集的情况)

注意因为2^p会超出数据范围所以还须要用高精度算法。

200. Cracking RSA

time limit per test: 0.25 sec.

memory limit per test: 65536 KB
input: standard

output: standard
The following problem is somehow related to the final stage of many famous integer factorization algorithms involved in some cryptoanalytical problems, for example cracking well-known RSA public key system. 



The most powerful of such algorithms, so called quadratic sieve descendant algorithms, utilize the fact that if n = pq where p and q are large unknown primes needed to be found out, then if v2=w2(mod n), u ≠ v (mod n) and u ≠ -v (mod n),
then gcd(v + w, n) is a factor of n (either p or q). 



Not getting further in the details of these algorithms, let us consider our problem. Given m integer numbers b1, b2, ..., bm such that all their prime factors are from the set of first t primes, the task is to find such a subset
S of {1, 2, ..., m} that product of bi for i from S is a perfect square i.e. equal to u2 for some integer u. Given such S we get one pair for testing (product of S elements stands for v when w is known from other steps of algorithms which
are of no interest to us, testing performed is checking whether pair is nontrivial, i.e. u ≠ v (mod n) and u ≠ -v (mod n)). Since we want to factor n with maximum possible probability, we would like to get as many such sets as possible. So the interesting
problem could be to calculate the number of all such sets. This is exactly your task. 


Input


The first line of the input file contains two integers t and m (1 ≤ t ≤ 100, 1 ≤ m ≤ 100). The second line of the input file contains m integer numbers bi such that all their prime factors are from t first primes (for example, if t = 3 all their
prime factors are from the set {2, 3, 5}). 1 ≤ bi ≤ 109 for all i. 


Output


Output the number of non-empty subsets of the given set {bi}, the product of numbers from which is a perfect square 




Sample test(s)


Input

3 4 9 20 500 3 
Output




#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x) const int maxn = 210; using namespace std; bool f[maxn+1000];
int k[maxn+1000];
int a[maxn][maxn];
int num[maxn];
int equ, var;
char str1[maxn], str2[maxn]; void Add(char a[], char b[], char c[])
{
int len1 = strlen(a);
int len2 = strlen(b);
int n = max(len1, len2);
int add = 0;
for(int i = 0; i < n; i++)
{
int cnt = 0;
if(i < len1) cnt += a[i]-'0';
if(i < len2) cnt += b[i]-'0';
cnt += add;
add = cnt/10;
c[i] = cnt%10+'0';
}
if(add) c[n++] = add+'0';
c[n] = 0;
} void Sub_1(char a[])
{
int s = 0;
while(a[s] == '0') s++;
a[s]--;
for(int i = 0; i < s; i++)
a[i] = '9';
int len = strlen(a);
while(len > 1 && a[len-1] == '0') len--;
a[len] = 0;
} void Prime()
{
int t = 0;
memset(f, false, sizeof(f));
for(int i = 2; i <= 1005; i++)
{
if(!f[i])
k[t++] = i;
for(int j = 0; j < t; j++)
{
if(i*k[j] > 1005)
break;
f[i*k[j]] = true;
if(i%k[j] == 0)
break;
}
}
} int Gauss()
{
int row, col;
int max_r;
row = col = 0;
while(row < equ && col < var)
{
max_r = row;
for(int i = row+1; i < equ; i++)
{
if(a[i][col]) max_r = i;
}
if(a[max_r][col] == 0)
{
col++;
continue;
}
if(max_r != row)
{
for(int j = col; j <= var; j++) swap(a[max_r][j], a[row][j]);
}
for(int i = row+1; i < equ; i++)
{
if(a[i][col] == 0) continue;
for(int j = col; j <= var; j++) a[i][j] ^= a[row][j];
}
col++;
row++;
}
return var-row;
} int main()
{
Prime();
int n, m;
while(cin >>n>>m)
{
memset(a, 0, sizeof(a));
for(int i = 0; i < m; i++) cin >>num[i];
equ = n;
var = m;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
int ans = 0;
while(num[j]%k[i] == 0)
{
ans ++;
num[j]/=k[i];
}
if(ans%2) a[i][j] = 1;
}
}
int N = Gauss();
strcpy(str1, "1");
for(int i = 0; i < N; i++)
{
Add(str1, str1, str2);
strcpy(str1, str2);
}
Sub_1(str1);
for(int i = strlen(str1)-1; i >= 0; i--) cout<<str1[i];
cout<<endl;
}
return 0;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

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

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

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

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

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

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

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出m个整理,因子全部为前t个素数.问有多少 ...

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

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

  5. HDU2449 Gauss Elimination 高斯消元 高精度 (C++ AC代码)

    原文链接https://www.cnblogs.com/zhouzhendong/p/HDU2449.html 题目传送门 - HDU2449 题意 高精度高斯消元. 输入 $n$ 个 $n$ 元方程 ...

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

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

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

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

  8. 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 ...

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

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

随机推荐

  1. C#语言基础原理及优缺点

    一.原理: C#是专门为.net程序框架而创造的语言. .net框架有ms的.netFramework:Mono的.NetFramework(也是符合.net IL语言,CTS规范,CLS规范, CL ...

  2. ECshop lib_base.php on line 1241 错误解决方法

    ECSHOP做的一个网站,突然报这个错误,整个网站打不开,后来找了很久,终于找到这个方法,亲测可用 Notice: Undefinedvariable: data in D:\wwwroot\KISS ...

  3. VMware workstation 安装错误提示1021解决方法

    Failed to create the requested registry key Key: Installer Error: 1021 解决方法:删除注册表--HKEY_LOCAL_MACHIN ...

  4. SecureCRT学习之道:SecureCRT 常用技巧

    快捷键: 1. ctrl + a :  移动光标到行首 2. ctrl + e :移动光标到行尾 3. ctrl + d :删除光标之后的一个字符 4. ctrl + w : 删除行首到当前光标所在位 ...

  5. Redhat 6.3中syslog信息丢失

    我们採用Linux的syslog来记录产品的debug log. 调用当中的一个可运行文件.运行完命令之后,查看debug log的信息,竟然从某一条log之后的log都丢失了.多次尝试后,发现每次都 ...

  6. LINQ to JavaScript 源码分析

    在.net平台工作一年有余,最喜欢的应属Linq特性 在几个移动端web小项目过程中,前端需要对json对象集合进行比较复杂的操作,为提高开发效率,引入了LINQ to Javascript,该项目地 ...

  7. hdu3452 无向树去掉最小的边集使不论什么叶子与根不连通 / 最小割

    思路一下就上来了,叶子向汇点连边,inf保证不会成为割,跑根到汇点最小割就可以.注意无向树双向建边.基础题,分分钟1A: #include<iostream> #include<qu ...

  8. 无状态会话bean(3)---远程业务接口(没有排版)

    迄今为止,我们仅仅讨论了使用一个本地业务接口的会话bean.在这样的情况下.本地意味着仅仅能由执行在同一个应用程序server实例的JavaEE组件声明会话bean的依赖性.比如.远程client不可 ...

  9. HDOJ 2665 Kth number

    静态区间第K小....划分树裸题 Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  10. Facebook Asynchronous Layout and Rending

    Facebook Asynchronous Layout and Rending by 吴雪莹 dispatch_async(backgroundQueue, ^{ storyNode = [[FBS ...