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,所以 ...
随机推荐
- IOS代码
//// MJViewController.m// UITableView-编辑模式//// Created by mj on 13-4-11.// Copyright (c) 2013年 itcas ...
- Android动画效果translate、scale、alpha、rotate
overridePendingTransition只支持android 2.0以上版本,动画效果在anim目录下的xml文件中定义,在程序中用AnimationUtils.loadAnimation( ...
- dp,px转换
public static int dip2px(Context context, float dpValue) { final float scale = context.getRes ...
- btr_pcur_t
/** Persistent cursor */ typedef struct btr_pcur_struct btr_pcur_t; /* The persistent B-tree cursor ...
- 实际举例C#引用类型和值类型的区别<网摘>
我们都知道,c#的两大数据类型分别为值类型和引用类型.很多人或许闭着眼睛都能说出值类型包括简单类型.结构体类型和枚举类型,引用类型包括自定义类.数组.接口.委托等,但是当被问及到二者之间的联系和区别, ...
- HDU 1425 sort 【哈希入门】
题意:给出n个数,输出前m大的数 和上一题一样,将输入的数加上一个极大地值作为地址 #include<iostream> #include<cstdio> #include&l ...
- 解析UML9种图的作用
本文和大家重点讨论一下UML9种图的概念,UML中有五类图,共有9种图形,每种图形都有各自的特点,下面就让我们一起来看一下这些图形特点的详细介绍吧. UML9种图简介 1.用例图 说明的是谁要使用系统 ...
- 模仿 "淘宝彩票" 的随机选球投注效果!
我个人比较喜欢看网页的效果,前几天看了淘宝的“淘宝彩票”,今天仿造做了一个,我觉得比淘宝的体验要好. 查看 “淘宝彩票” 的网页源码发现,主要是用到了Css3 transform 的 Matrix 来 ...
- LeetCode: 3SumClosest
Title : Given an array S of n integers, find three integers in S such that the sum is closest to a g ...
- 漂亮灵活设置的jquery通知提示插件toastr
toastr是一款非常棒的基于jquery库的非阻塞通知提示插件,toastr可设定四种通知模式:成功,出错,警告,提示,而提示窗口的位置,动画效果都可以通过能数来设置,在官方站可以通过勾选参数来生成 ...