HDU 5833 Zhu and 772002 (高斯消元)
Zhu and 772002
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5833
Description
Zhu and 772002 are both good at math. One day, Zhu wants to test the ability of 772002, so he asks 772002 to solve a math problem.
But 772002 has a appointment with his girl friend. So 772002 gives this problem to you.
There are n numbers a1,a2,...,an. The value of the prime factors of each number does not exceed 2000, you can choose at least one number and multiply them, then you can get a number b.
How many different ways of choices can make b is a perfect square number. The answer maybe too large, so you should output the answer modulo by 1000000007.
Input
First line is a positive integer T , represents there are T test cases.
For each test case:
First line includes a number n(1≤n≤300),next line there are n numbers a1,a2,...,an,(1≤ai≤1018).
Output
For the i-th test case , first output Case #i: in a single line.
Then output the answer of i-th test case modulo by 1000000007.
Sample Input
2
3
3 3 4
3
2 2 2
Sample Output
Case #1:
3
Case #2:
3
Source
2016中国大学生程序设计竞赛 - 网络选拔赛
##题意:
给出n个数,求有多少种方式使得选取的数的乘积是一个完全平方数.
##题解:
原题:[UVA11542](http://acm.hust.edu.cn/vjudge/problem/34393) (大白书P160例题25)
转化成异或方程组,并用高斯消元求解矩阵的秩.
很遗憾,上述知识点都不会....
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 2100
#define mod 1000000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
typedef long long ll;
using namespace std;
typedef int Matrix[maxn][maxn];
int prime[maxn], vis[maxn];
Matrix A;
int get_primes(int m) {
memset(vis, 0, sizeof(vis));
int cnt = 0;
for (int i = 2; i < m; i++) {
if (!vis[i]) {
prime[cnt++] = i;
for (int j = i * i; j < m; j += i)
vis[j] = 1;
}
}
return cnt;
}
int gauss(Matrix A, int m, int n) {
int i = 0, j = 0, k , r, u;
while (i < m && j < n) {
r = i;
for (k = i; k < m; k++)
if (A[k][j]) {
r = k;
break;
}
if (A[r][j]) {
if (r != i)
for (k = 0; k <= n; k++)
swap(A[r][k], A[i][k]);
for (u = i+1; u < m; u++)
if (A[u][j])
for (k = i; k <= n; k++)
A[u][k] ^= A[i][k];
i++;
}
j++;
}
return i;
}
LL quickmod(LL a,LL b,LL m)
{
LL ans = 1;
while(b){
if(b&1){
ans = (ansa)%m;
b--;
}
b/=2;
a = aa%m;
}
return ans;
}
int main() {
//freopen("in.txt", "r", stdin);
int m = get_primes(2100);
int t;
int ca = 1;
scanf("%d", &t);
while (t--) {
printf("Case #%d:\n", ca++);
int n, maxp = 0;;
ll x;
scanf("%d", &n);
memset(A, 0, sizeof(A));
for (int i = 0; i < n; i++) {
scanf("%lld", &x);
for (int j = 0; j < m; j++)
while (x % prime[j] == 0) {
maxp = max(maxp, j);
x /= prime[j];
A[j][i] ^= 1;
}
}
int r = gauss(A, maxp+1, n);
LL ans = quickmod(2, (LL)(n-r), mod) - 1;
//printf("%lld\n", (1LL << (n-r)) - 1);
printf("%lld\n", ans);
}
return 0;
}
HDU 5833 Zhu and 772002 (高斯消元)的更多相关文章
- 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 (高斯消元-自由元)
pro:给定N个数Xi(Xi<1e18),保证每个数的素因子小于2e3:问有多少种方案,选处一些数,使得数的乘积是完全平方数.求答案%1e9+7: N<300; sol:小于2e3的素数只 ...
- 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 ccpc网络赛 高斯消元法
传送门:hdu 5833 Zhu and 772002 题意:给n个数,每个数的素数因子不大于2000,让你从其中选则大于等于1个数相乘之后的结果为完全平方数 思路: 小于等于2000的素数一共也只有 ...
- HDU 5755 Gambler Bo(高斯消元)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5755 [题目大意] 一个n*m由0,1,2组成的矩阵,每次操作可以选取一个方格,使得它加上2之后对 ...
- HDU 4818 RP problem (高斯消元, 2013年长春区域赛F题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4818 深深地补一个坑~~~ 现场赛坑在这题了,TAT.... 今天把代码改了下,过掉了,TAT 很明显 ...
- ACM学习历程—HDU 3949 XOR(xor高斯消元)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3949 题目大意是给n个数,然后随便取几个数求xor和,求第k小的.(重复不计算) 首先想把所有xor的 ...
- 2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)
题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的 ...
- HDU 3571 N-dimensional Sphere(高斯消元 数论题)
这道题算是比较综合的了,要用到扩展欧几里得,乘法二分,高斯消元. 看了题解才做出来orz 基本思路是这样,建一个n*(n-1)的行列式,然后高斯消元. 关键就是在建行列式时会暴long long,所以 ...
随机推荐
- [转载]深入理解JAVA的接口和抽象类
深入理解Java的接口和抽象类 对于面向对象编程来说,抽象是它的一大特征之一.在Java中,可以通过两种形式来体现OOP的抽象:接口和抽象类.这两者有太多相似的地方,又有太多不同的地方.很多人在初学的 ...
- Windows下搭建MySql Master-Master Replication
1.首先下载最新版的MySql Server (http://dev.mysql.com/downloads/windows/installer/) 2.安装MySql Server到两台机器上 My ...
- 购买使用Linode VPS必须知晓的十个问题
Linode是国外非常著名的VPS商之一,目前在国内站长圈中备受推崇.有许多站长已经购买了Linode VPS,但是部分站长由于中英语言不通,对Linode的政策不了解,从而造成了许多不必要的损失.本 ...
- velocity加减运算注意格式 ,加减号的左右都要有空格
velocity加减运算注意格式 ,加减号的左右都要有空格 #set( $left= $!biz.value - $vMUtils.getReturnMoney($!biz.billBuy) )
- hibernate 中id生成策略
数据库的设计和操作中,我们通常会给表建立主键. 主键,可以分为自然主键和代理主键. 自然主键表示:采用具有业务逻辑含义的字段作为表的主键.比如在用户信息表中,采用用户的身份证号码作为主键.但是这样一来 ...
- WebClient+Fiddler2完美搭配下载远程页面信息
WebClient可以下载远程页面信息,这个大家应该都知道,核心代码如下: WebClient web = new WebClient(); string url = String.Format(&q ...
- MasterPage的自身Bug还是?
如果不想每个页面都设置css样式,那就在MasterPage设置即可,但是有个问题就是路径并不能识别正确,所以必须让你的页面和MasterPage的页面在平级的位置. 例如MasterPage.mas ...
- Mybatis学习——一对一关联表查询
1.SQL语句建表 CREATE TABLE teacher( t_id ) ); CREATE TABLE class( c_id ), teacher_id INT ); ALTER TABLE ...
- 四、oracle基本sql语句和函数详解
一.oracle常用数据类型 一. 数据定义语言(ddl) 数据定义语言ddl(data definition language)用于改变数据库结构,包括创建.更改和删除数据库对象. 用于操纵表结构 ...
- OC中两种单例实现方式
OC中两种单例实现方式 写在前面 前两天探索了一下C++ 的单例,领悟深刻了许多.今天来看看OC中的单例又是怎么回事.查看相关资料,发现在OC中一般有两种实现单例的方式,一种方式是跟C++ 中类似的常 ...