ZOJ 2320 Cracking' RSA
其次布尔线性方程组,高斯消元。这道题目的关键部分是看的神牛watashi的思路。另附上watashi的思路
我把他的java模板翻译成了C++的了。。。存起来以后当模板用。。。a[i][j]表示第i个数含有质数p[j]的个数,奇数个的话就是true,偶数个就是false。这样的话对于布尔方程组有,能被完全消掉的数就可以和用来消去这个数的数组成一个完全平方数。这样的话就是找多少个数能够被完全消去。这样的话答案就是2^(n-r)-1了。
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define CLR(a, b) memset(a, b, sizeof(a)) using namespace std;
const int N = 120;
const int M = 600;
bool a[N][N];
bool isp[M];
int p[N], cnt; void get_P()
{
CLR(isp, true);cnt = 0;
isp[0] = isp[1] = false;
for(int i = 2; i < M; i ++)
{
if(isp[i])
{
p[cnt ++] = i;
for(int j = i * i; j < M; j += i) isp[j] = false;
}
}
} int gauss(int N, int M)
{
int r, c, pvt;
bool flag;
for (r = 0, c = 0; r < N && c < M; ++ r, ++ c) {
flag = false;
for (int i = r; i < N; ++ i)
if (a[i][c]) {
flag = a[pvt=i][c];
break;
}
if (!flag) {
r--; continue;
}
if (pvt != r)
for (int j = r; j <= M; ++j) swap(a[r][j], a[pvt][j]);
for (int i = r+1; i < N; ++i)
if(a[i][c])
{
a[i][c] = false;
for (int j = c+1; j <= M; ++j) {
if(a[r][j]) a[i][j] = !a[i][j];
}
}
}
return r;
} int ans[N], MOD = 10000; void pt(int n)
{
int bit = 0, cr = 0;
CLR(ans, 0);ans[0] = 1;
for(int i = 0; i < n; i ++)
{
cr = 0;
for(int j = 0; j <= bit; j ++)
{
ans[j] = ans[j] * 2 + cr;
cr = ans[j] / MOD;
ans[j] %= MOD;
}
if(cr) ans[++ bit] = cr;
}
int s = 0;
while(!ans[s]) s ++;ans[s] --;
for(int i = s - 1; i >= 0; i --)
{
ans[s] = MOD - 1;
}
//cout << "bit " << bit << endl;
printf("%d", ans[bit]);
for(int i = bit - 1; i >= 0; i --)
{
int tmp = ans[i], cnt = 0;
while(tmp){ tmp /= 10; cnt ++;}
for(int j = 0; j < 4 - cnt; j ++) putchar('0');
printf("%d", ans[i]);
}
puts("");
} int main()
{
int t, n, m;get_P();
scanf("%d", &t);
while(t --)
{
scanf("%d%d", &m, &n);
for(int i = 0; i < n; i ++)
{
int tmp;
scanf("%d", &tmp);
for(int j = 0; j < m; j ++)
{
a[i][j] = false;
while(tmp % p[j] == 0)
{
tmp /= p[j];
a[i][j] = !a[i][j];
}
}
}
n -= gauss(n, m);
pt(n);
if(t) puts("");
}
}
ZOJ 2320 Cracking' RSA的更多相关文章
- SGU 200. Cracking RSA(高斯消元+高精度)
标题效果:鉴于m整数,之前存在的所有因素t素数.问:有多少子集.他们的产品是数量的平方. 解题思路: 全然平方数就是要求每一个质因子的指数是偶数次. 对每一个质因子建立一个方程. 变成模2的线性方程组 ...
- SGU 200. Cracking RSA (高斯消元求自由变元个数)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=200 200. Cracking RSA time limit per test: ...
- Acdream1217 Cracking' RSA(高斯消元)
题意:给你m个数(m<=100),每个数的素因子仅来自于前t(t<=100)个素数,问这m个数的非空子集里,满足子集里的数的积为完全平方数的有多少个. 一开始就想进去里典型的dp世界观里, ...
- SGU 200.Cracking RSA(高斯消元)
时间限制:0.25s 空间限制:4M 题意: 给出了m(<100)个数,这m个数的质因子都是前t(<100)个质数构成的. 问有多少个这m个数的子集,使得他们的乘积是完全平方数. Solu ...
- SGU 200 Cracking RSA (高斯消元)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意:给出m个整理,因子全部为前t个素数.问有多少 ...
- ASC #1
开始套题训练,第一套ASC题目,记住不放过每一题,多独立思考. Problem A ZOJ 2313 Chinese Girls' Amusement 循环节 题意:给定n,为圆环长度,求k < ...
- July 【补题】
A(zoj 3596) bfs,记忆搜都可以, 按余数来记录状态. B(zoj 3599) 博弈,跳过 C(zoj 3592) 简单dp,题意不好懂 D(zoj 3602) 子树哈希, 对根的左右儿子 ...
- ACdrea 1217---Cracking' RSA(高斯消元)
ACdrea 1217---高斯消元 Description The following problem is somehow related to the final stage of many ...
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
随机推荐
- VC/MFC分割字符串(SplitString)返回CStringArray
引自:http://bbs.csdn.net/topics/60321228 原版: CStringArray* SplitString(CString string, char pattern) { ...
- Codeforces Round #353 (Div. 2) B. Restoring Painting 水题
B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
- noip 1995 灯的排列问题 排列组合 DFS
题目描述 设在一排上有N个格子(N≤20),若在格子中放置有不同颜色的灯,每种灯的个数记为N1,N2,……Nk(k表示不同颜色灯的个数). 放灯时要遵守下列规则: ①同一种颜色的灯不能分开: ②不同颜 ...
- Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- ASP.NET MVC的请求处理流程
(1)用户打开浏览器,在地址栏输入某个网址URL并回车,浏览器便开始向该URL指向的服务器发送HTTP请求(一般是GET方式).(2)服务器端的网站服务系统(IIS)接收到该请求,先检查自己是否认识该 ...
- iOS学习之WebView的使用 (主要是下面的全屏半透明实现)
1.使用UIWebView加载网页 运行XCode 4.3,新建一个Single View Application,命名为WebViewDemo. 2.加载WebView 在ViewControlle ...
- Redis在Windows+linux平台下的安装配置(转)
window平台Redis安装 下载地址: http://code.google.com/p/servicestack/wiki/RedisWindowsDownload Redis文件夹有以下几个文 ...
- MP1593 RT8272 ACT4070 制作的DC-DC稳压电源
http://www.ideyi.org/article/11-05/2575971305526398.html?sort=2068_2073_2092_0 MP1593制作的DC-DC稳压电源,这款 ...
- PostgreSQL 资料库
https://yq.aliyun.com/articles/59251 https://github.com/digoal/blog/blob/master/201609/20160929_02.m ...