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,所以 ...
随机推荐
- PHP无限极分类生成树方法
你还在用浪费时间又浪费内存的递归遍历无限极分类吗,看了该篇文章,我觉得你应该换换了.这是我在OSChina上看到的一段非常精简的PHP无限极分类生成树方法,整理分享了. function genera ...
- 07-语言入门-07-A Famous Music Composer
题目地址: http://blog.csdn.net/sevenmit/article/details/8231994 描述 Mr. B is a famous music composer. On ...
- bzoj3140
首先考虑二维的情况 min(x,y)也就意味着确定最小后,另外一维肯定打满 然后最小那个如果是k的话就相当于用k*1次——这不就是行列覆盖吗,二分图秒之 三维呢?考虑到a*b*c<=5000也就 ...
- js 跨域的问题 (同一个主域名不同的二级域名下的跨域问题) 解决 WdatePicker.js my97日期选择控件
例如域名是 a.xx.com 和 b.xx.com 如果一个页面中引入多个iframe,要想能够操作所有iframe,必须都得设置相同domain. 如果iframe的时候 a包含b 为 ...
- Jquery 弹出提示框输入插件 apprise 修改中文按钮以及使用说明
apprise的使用非常简单,引入js脚本和css <script type="text/javascript" src="/js/apprise-1.5.fu ...
- Java [leetcode 4] Median of Two Sorted Arrays
问题描述: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of t ...
- ffmpeg Windows下采集摄像头一帧数据,并保存为bmp图片
这里请注意,在编译ffmpeg时,不要使用--disable-devices选项. 使用 --enable-encoder=rawvideo --enable-decoder=rawvideo 启用r ...
- <五>面向对象分析之UML核心元素之边界
一:基本概念
- 鼠标悬停css3动画效果
下载Demo 效果预览 html: <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- JS动态呈现还可以输入字数
现在觉得当我们使用js或者jquery来呈现一个动态效果时,主要还是要想清楚它的思想.它的原理.而动态呈现输入字数,其实就是给它设置一个最大输入字数,然后获取已输入的字数,自然想做什么都可以. < ...