hdu5833Zhu and 772002
来源:互联网 发布:网络剧排行榜2016 编辑:程序博客网 时间:2024/05/16 08:29
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5833
题意:给定n个数,保证没有素因子大于2000,求选择任意个数字出来(至少选1个)使得选出来的数乘起来为完全平方数。
分析:2000以内的素因子只有303个,要构成完全平方数只需要使得出现的素因子次数为偶数次即可,对每个数对于每个素数的奇偶性列方程式求方程组的自由元个数即可。
代码:
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<vector>#include<string>#include<stdio.h>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=2010;const int mod=1000000007;const int MOD1=1000000007;const int MOD2=1000000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=1000000007;const int INF=1000000010;const ll MAX=1ll<<55;const double eps=1e-5;const double inf=~0u>>1;const double pi=acos(-1.0);typedef double db;typedef unsigned int uint;typedef unsigned long long ull;int k,pri[N],q[N],e[N];void deal(int n) { int i,j;k=0;e[0]=1; for (i=1;i<=n;i++) e[i]=(e[i-1]*2)%mod; for (i=2;i<=n;i++) { if (!q[i]) pri[++k]=i; for (j=1;j<=k;j++) { if (pri[j]*i>n) break ; q[pri[j]*i]=1; if (i%pri[j]==0) break ; } }}int a[350][350],f[350][350];int get(ll x,int j) { int ret=0; while (x%pri[j]==0) { ret^=1;x/=pri[j]; } return ret;}int gauss(int n,int m) { int i=1,j,k,h,w=0; for (j=1;j<m;j++,w=0) { for (k=i;k<=n;k++) if (a[k][j]) w=k; if (w) { for (k=j;k<=m;k++) swap(a[i][k],a[w][k]); for (k=i+1;k<=n;k++) if (a[k][j]) { for (h=j;h<=m;h++) a[k][h]^=a[i][h]; } i++; } if (i>n) break ; } return n-i+1;}int main(){ int i,j,n,t,Z,ca; ll x; scanf("%d", &t); deal(2000); for (ca=1;ca<=t;ca++) { scanf("%d", &n); for (i=1;i<=n;i++) { scanf("%I64d", &x);a[i][k+1]=0; for (j=1;j<=k;j++) a[i][j]=get(x,j); } Z=gauss(n,k+1); printf("Case #%d:\n%d\n", ca, (e[Z]-1+mod)%mod); } return 0;}
0 0
- hdu5833Zhu and 772002
- Zhu and 772002
- Zhu and 772002
- hdu5833 Zhu and 772002
- Zhu and 772002
- hdu5833 Zhu and 772002
- Zhu and 772002
- Zhu and 772002 HDU
- Zhu and 772002 HDU
- " and '
- $* and $@
- AND
- AND
- & and &&
- ""and ‘’
- HDU 5833 Zhu and 772002
- HDU 5833 Zhu and 772002
- HDU 5833 Zhu and 772002
- FORMS进阶之——规范化触发器内容
- init
- Majority Element II
- HDU 5842 Lweb and String (水题)
- jsp到javabean数据传递
- hdu5833Zhu and 772002
- Json使用的困惑
- FORM开发入门1——利用单张表作源
- 测试人员应该具备哪些软技能
- 网络与RPC
- 可靠性测试和软件性能测试数据总结
- myeclipse乱码处理
- FORM开发入门2——利用单张视图作源
- Openwrt包和源码地址