hdu5833 Zhu and 772002
来源:互联网 发布:淘宝香火符咒西极飞飞 编辑:程序博客网 时间:2024/06/05 04:04
题目大意:从n个数a1,a2,…,an里选出若干个数(至少选一个),然后把选出的数乘起来得到b,问b是完全平方数的取数方法有多少种。每个数的质因子不超过2000,答案模上1000000007。
这道题目和POJ1830开关问题类似。首先,n个数中每个数都有取与不取两种操作,令向量
题目中说质因子的大小不会超过2000,分解质因子可行,对每个数分解质因子即可得到矩阵
#include<iostream>#include<algorithm>#include<cmath>#include<cstring>using namespace std;typedef unsigned long long ull;const int maxn = 2001, mod = 1000000007;bool isnpri[maxn];int prime[maxn], k;inline void getPrime(){ for (int i = 2; i < maxn; i++) { if (!isnpri[i]) prime[k++] = i; for (int j = 0; j < k && i*prime[j] < maxn; j++) { isnpri[i*prime[j]] = true; if (i%prime[j] == 0) break; } }}ull a[300];int fac[maxn][300];inline void factor(int n){ ull now = a[n]; for (int i = 0; i < k; i++) while (now%prime[i] == 0) fac[i][n] ^= 1, now /= prime[i];}inline int gauss(int n){ int i = 0, j = 0; while (j < n) { int id = i; for (int k = i; k < ::k; k++) if (abs(fac[k][j])) id = k; if (id != i) { for (int k = j; k < n; k++) swap(fac[i][k], fac[id][k]); } if (fac[i][j] == 0) { j++; continue; } for (int k = i + 1; k < ::k; k++) { if (fac[k][j] == 0) continue; for (int l = j; l < n; l++) fac[k][l] ^= fac[i][l]; } i++, j++; } return n - i;}inline ull pow_mod(ull x, ull n){ ull ret = 1; while (n) { if (n & 1) ret = ret*x%mod; x = x*x%mod; n >>= 1; } return ret;}int main(){ getPrime(); //筛出2000内的素数 int T, t = 0; cin >> T; while (T--) { memset(fac, 0, sizeof(fac)); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; factor(i); //分解质因数 } int free_element = gauss(n); ull ans = pow_mod(2, free_element) - 1; cout << "Case #" << ++t << ":\n"; cout << ans << endl; } return 0;}
0 0
- hdu5833 Zhu and 772002
- hdu5833 Zhu and 772002
- hdu5833 Zhu and 772002 【高斯消元解异或方程组】
- HDU5833-Zhu and 772002(高斯消元)
- 2016中国大学生程序设计竞赛 - 网络选拔赛 hdu5833 Zhu and 772002
- hdu5833 Zhu and 772002 (高斯消元的简单应用)
- 2016中国大学生程序设计竞赛 - 网络选拔赛 1002 Zhu and 772002 hdu5833
- HDU5833(2016CCPC网赛)——Zhu and 772002(异或方程组,素数分解)
- ACM高斯消元法 亦或方程组求秩 (HDU5833 Zhu and 772002)
- Zhu and 772002
- Zhu and 772002
- Zhu and 772002
- Zhu and 772002
- Zhu and 772002 HDU
- Zhu and 772002 HDU
- HDU 5833 Zhu and 772002
- HDU 5833 Zhu and 772002
- HDU 5833 Zhu and 772002
- [iOS]百分比编码
- 选项卡实现(使用this)
- Python中文件读取方法read(),readline(),readlines()的区别
- Swift-->Http网络请求(NSURLSession, Alamofire)
- leetcode_c++:树:Populating Next Right Pointers in Each Node II(117)
- hdu5833 Zhu and 772002
- Interllij 自定义模板
- savedInstanceState
- Ubuntu 下 网易云音乐使用体验
- 解决nagios报错:./stdio.h:456:1: error: 'gets' undeclared here (not in a function)的问题
- 二、谈谈算法
- JavaScript性能优化技巧之函数节流
- 写开源项目步骤(上传github、发布到jcenter、录屏gif)
- c与sv混合仿真的简单示例