HDU 5833 Zhu and 772002

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

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.

Zhu和772002都擅长数学。 某天,Zhu想试试772002的能耐,就给772002出了道数学题。

但772002与女票有约在先,果断甩锅予你。

有n个数a1,a2,...,an每个数的质因数不超过2000,你可以选择至少一个数并将所选的数相乘,得到b

有多少种选择方式可以使b为完全平方数。结果可能非常大,输出时模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).

第一行是一个整数T(T≤100),表示有T个测试用例的数量。

对于每个测试用例:

第一行有一个整数n(1≤n≤300),下一行有n个数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.

对于第i个测试用例,先输出一行Case #i:。

然后输出第i个测试用例的答案模1000000007后的结果。

Sample Input - 输入样例

Sample Output - 输出样例

2
3
3 3 4
3
2 2 2

Case #1:
3
Case #2:
3

【题解】

  分解质因数 + 高斯消元

  对于容易一个输入的数进行分解质因数,保存到矩阵的各个行中。

  每个数都能看作若干个质数相乘,若每个质数的指数均为偶数,这个数即是完全平方数。因此用10表示奇偶,每个数的合并/化简就能用异或来操作。

  然后用异或高斯消元,得到矩阵的秩r,接着得到(n - r)个可自由组合的完全平方数。最后组合数求和,去掉什么都不选的情况,结果为2- 1。

  (啪!迷之巴掌)

  好吧,其实我一开始根本不知道高斯消元是什么鬼。刚刚开始的理解就是分解质因数(形成多项式),压入矩阵方便求基底(当成向量来看),然后默默地发现高斯消元就是矩阵化简吧……

【代码 C++】

  1. #include <cstdio>
  2. #include <cstring>
  3. #define pMX 2005
  4. #define mod 1000000007
  5. int prim[] = { }, iP, mtx[][];
  6. void getPrim() {
  7. int i, j;
  8. bool mark[pMX];
  9. memset(mark, , sizeof(mark));
  10. for (i = ; i < pMX; i += ) {
  11. if (mark[i]) continue;
  12. prim[++iP] = i;
  13. for (j = i << ; j < pMX; j += i) mark[j] = ;
  14. }
  15. }
  16. void tPrim(int y, __int64 a) {
  17. int i, j;
  18. for (i = ; i <= iP && a >= prim[i]; ++i) {
  19. if (a / prim[i] * prim[i] == a) {
  20. for (j = ; a / prim[i] * prim[i] == a; a /= prim[i]) ++j;
  21. mtx[y][i] = j & ;
  22. }
  23. }
  24. }
  25. int mTS(int n){
  26. bool inUS[]; memset(inUS, , sizeof(inUS));
  27. int size = , i, j, k, ik;
  28. for (j = ; j <= iP; ++j){
  29. for (i = ; i < n; ++i){
  30. if (inUS[i] == && mtx[i][j] == ) break;
  31. }
  32. if (i == n) continue;
  33. inUS[i] = ; ++size;
  34. for (k = ; k < n; ++k){
  35. if (inUS[k] || mtx[k][j] == ) continue;
  36. for (ik = j; ik <= iP; ++ik) mtx[k][ik] ^= mtx[i][ik];
  37. }
  38. }
  39. return n - size;
  40. }
  41. __int64 qMod(__int64 a, int n){
  42. __int64 opt = ;
  43. while (n){
  44. if (n & ) opt = (opt*a) % mod;
  45. n >>= ;
  46. a = (a*a) % mod;
  47. }
  48. return opt;
  49. }
  50. int main() {
  51. getPrim();
  52. int t, iT, i, n;
  53. __int64 ai;
  54. scanf("%d", &t);
  55. for (iT = ; iT <= t; ++iT) {
  56. printf("Case #%d:\n", iT);
  57. memset(mtx, , sizeof(mtx));
  58. scanf("%d", &n);
  59. for (i = ; i < n; ++i){
  60. scanf("%I64d", &ai);
  61. tPrim(i, ai);
  62. }
  63. printf("%I64d\n", qMod(, mTS(n)) - );
  64. }
  65. return ;
  66. }

HDU 5833 Zhu and 772002的更多相关文章

  1. hdu 5833 Zhu and 772002 ccpc网络赛 高斯消元法

    传送门:hdu 5833 Zhu and 772002 题意:给n个数,每个数的素数因子不大于2000,让你从其中选则大于等于1个数相乘之后的结果为完全平方数 思路: 小于等于2000的素数一共也只有 ...

  2. HDU 5833 Zhu and 772002 (高斯消元)

    Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...

  3. hdu 5833 Zhu and 772002 高斯消元

    Zhu and 772002 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test ...

  4. HDU 5833 Zhu and 772002(高斯消元)

    题意:给n个数,从n个数中抽取x(x>=1)个数,这x个数相乘为完全平方数,求一共有多少种取法,结果模1000000007. 思路:每个数可以拆成素数相乘的形式,例如: x1 2=2^1 * 3 ...

  5. HDU 5833 Zhu and 772002 (数论+高斯消元)

    题目链接 题意:给定n个数,这n个数的素因子值不超过2000,从中取任意个数使其乘积为完全平方数,问有多少种取法. 题解:开始用素筛枚举写了半天TLE了,后来队友说高斯消元才想起来,果断用模板.赛后又 ...

  6. hdu 5833 Zhu and 772002 异或方程组高斯消元

    ccpc网赛卡住的一道题 蓝书上的原题 但是当时没看过蓝书 今天又找出来看看 其实也不是特别懂 但比以前是了解了一点了 主要还是要想到构造异或方程组 异或方程组的消元只需要xor就好搞了 数学真的是硬 ...

  7. HDU - 5833: Zhu and 772002 (高斯消元-自由元)

    pro:给定N个数Xi(Xi<1e18),保证每个数的素因子小于2e3:问有多少种方案,选处一些数,使得数的乘积是完全平方数.求答案%1e9+7: N<300; sol:小于2e3的素数只 ...

  8. HDU 5833 Zhu and 772002 ——线性基

    [题目分析] 这题貌似在UVA上做过,高精度高斯消元. 练习赛T2,然后突然脑洞出来一个用Bitset的方法. 发现代码只需要30多行就A掉了 Bitset大法好 [代码] #include < ...

  9. 【HDU 5833】Zhu and 772002(异或方程组高斯消元)

    300个最大质因数小于2000的数,选若干个它们的乘积为完全平方数有多少种方案. 合法方案的每个数的质因数的个数的奇偶值异或起来为0. 比如12=2^2*3,对应的奇偶值为01(2的个数是偶数为0,3 ...

随机推荐

  1. Python File.readlines() 方法

    python3的用法:

  2. MAC常用快捷键

    1.F11 用于当前界面与桌面进行切换,Command-M 最小化窗口,Option-Command-M 最小化所有窗口,Command-数字 切换数字指定的网页列表 Shift-Command-D ...

  3. Dijkstra 算法、Kruskal 算法、Prim算法、floyd算法

    1.dijkstra算法 算最短路径的,算法解决的是有向图中单个源点到其他顶点的最短路径问题. 初始化n*n的数组. 2.kruskal算法 算最小生成树的,按权值加入 3.Prim算法 类似dijk ...

  4. org.hibernate.PropertyNotFoundException:could not find a getter for name in class ....

    Hibernate创建持久化类须符合JavaBean的规范,"get","set"后面紧跟属性的名字,并且属性名的首字母为大写.如果不遵守这个规则,Hibern ...

  5. Python精神

    [root@LDAP_slave ~]# python -c "import this" The Zen of Python, by Tim Peters Beautiful is ...

  6. HDU 1827:Summer Holiday(强连通)

    http://acm.hdu.edu.cn/showproblem.php?pid=1827 思路:强连通分量缩点后找入度为0的点,然后对于属于该强连通分量的找一个最小耗费的入口. #include ...

  7. pgadmin(IDE)工具连接postgres数据库

    1. 下载软件        软件地址:http://www.pgadmin.org/download/pgagent.php   2.安装软件    安装过程:略    打开软件64位会出现  “无 ...

  8. linux中利用awk对数组进行排序

    数组 在排序前需要对数组有所了解,数组是用于存储一系列值得变量,这些值之间通常是由联系的,可通过索引来访问数组的值,索引需要用括号括起来,基本格式如下: array[index]=value awk数 ...

  9. Git and GitHub

    1.GitHub 创建一个仓库 2.进入本地要管理的某个文件夹下,感觉目录的操作命令和linux里面差不多, $git init 此时该文件下就会多出一个.git的文件 3.进入要上传的仓库,右键gi ...

  10. 【转】Eclipse插件大全介绍及下载地址

    转载地址:http://developer.51cto.com/art/200906/127169.htm 尚未一一验证. eclipse插件大全介绍,以及下载地址 Eclipse及其插件下载网址大全 ...