hdu 5833 Zhu and 772002 高斯消元
Zhu and 772002
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.
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).
Then output the answer of i-th test case modulo by 1000000007.
3
3 3 4
3
2 2 2
3
Case #2:
3
题意:
给你n个数,每个数的素数因子最大不超过2000,从n个数取出任意个至少一个,问有多少种方案使得数的乘积为完全平方数。
题解:
将所有素数处理出来
答案就是 每种素数个数为偶数个
将每个素数使用个数设为x 那么最终mod 2 = 0
那么有303个这样的方程
高斯消元求解异或方程组
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18;
const double Pi = acos(-1.0);
const int N = 2e3+, M = 1e6, mod = , inf = 2e9; int p[N],H[N],cnt,A[][],mx,ini[N];
LL a[N];
void init() {
for(int i = ; i <= ; ++i) {
if(!H[i]) {
p[cnt++] = i;
for(int j = i+i; j <= ; j += i) {
H[j] = ;
}
}
}
ini[] = ;
for(int i = ; i<= ; ++i) ini[i] = ini[i-]*%mod;
}
LL Guass(int n,int m) {
int i, j;
for(i = , j = ; i < n && j < m; ) {
int x = -;
for(int k = i; k < n; ++k) {
if(A[k][j]) {
x = k;
break;
}
}
if(x == -) {
++j;
continue;
}
for(int k = ; k <= m; ++k) swap(A[i][k],A[x][k]);
for(int u = i+; u < n; ++u) {
if(A[u][j]) {
for(int k = ; k <= m; ++k) {
A[u][k] ^= A[i][k];
}
}
}
++i;
++j;
}
return m-i;
}
int main() {
int T,cas = ,n;
init();
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
mx = ;
for(int i = ; i < n; ++i) scanf("%I64d",&a[i]);
memset(A,,sizeof(A));
for(int i = ; i < n; ++i) {
for(int j = ; j < cnt; ++j) {
while(a[i] % p[j] == ) {
A[j][i] ^= ;
a[i] /= p[j];
mx = max(mx,j+);
}
}
}
printf("Case #%d:\n",cas++);
cout<<ini[Guass(mx,n)] - <<endl;
}
return ;
}
hdu 5833 Zhu and 772002 高斯消元的更多相关文章
- 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 5833 Zhu and 772002 (高斯消元)
Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...
- 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,所以 ...
随机推荐
- 基础知识(javaWeb工程目录结构)及各文件夹的作用
在Eclipse中只要创建一个Dynamic Web Project,就可以根据创建向导创建出一个典型Java Web站点的目录结构.除非有特殊需要,在大多数情况下都没有必要修改这个目录结构,这也是W ...
- poj1177
题意:在平面直角坐标系内给出一些与坐标轴平行的矩形,将这些矩形覆盖的区域求并集,然后问这个区域的周长是多少.(边与边重合的地方不计入周长) 分析:线段树.曾经做过类似的求矩形覆盖的总面积的题.这道题同 ...
- 回调函数中使用MFC类的成员或对话框控件的简单方法
在MFC的很多程序中,常常需要在回调函数中调用MFC类的类成员变量.类成员函数,亦或者对话框控件的句柄.由于回调函数是基于C编程的Windows SDK的技术,而类成员又有this指针客观条件限制.. ...
- nginx服务器绑定域名和设置根目录的方法
nginx服务器绑定域名以及设置根目录非常方便,首先进入nginx安装目录,然后执行 vim conf/nginx.conf 打开nginx的配置文件,找到 server { ..... ..... ...
- Divide and Conquer:River Hopscotch(POJ 3258)
去掉石头 题目大意:一群牛在河上的石头上跳来跳去,现在问你如何通过去掉M个石头,使得牛跳过石头的最短距离变得最大? 这一题比较经典,分治法的经典,二分法可以很方便处理这个问题,我们只要明白比较函数这 ...
- Mathematics:Dead Fraction(POJ 1930)
消失了的分式 题目大意:某个人在赶论文,需要把里面有些写成小数的数字化为分式,这些小数是无限循环小数(有理数),要你找对应的分母最小的那个分式(也就是从哪里开始循环并不知道). 一开始我也是蒙了,这尼 ...
- C Primer Plus_第三章_数据和C_复习题与编程练习
Review long代替int类型变量的原因是什么? 在您的系统中,long可以容纳比int更大的数:如果您确实需要处理更大的值,那么使用一种在所有系统上都保证至少是32位的类型会使程序的可移植性更 ...
- EF的各种删除方法
//2.1检查 id 是否存在 //2.2执行删除 Models.Student stu = new Models.Student() { Id = id }; //db.Students.Attac ...
- 【leetcode】 Palindrome Partitioniong (middle) (*^__^*)
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- 【leetcode】 Letter Combinations of a Phone Number(middle)
Given a digit string, return all possible letter combinations that the number could represent. A map ...