1801: Mr. S’s Romance

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 15  Solved: 5
[Submit][Status][Web Board]

Description

Mr.
S is a young math professor who is famous for being crazy about
collecting prime numbers. Once he met a number, he would first divide it
into several prime numbers and then push them into his magic box. Every
week, Mr. S  sell out the primes in his box to earn money.

Today is August 22th, which is an important day to Mr. S because it’s his girl friend’s
birthday. She is a perfect girl, so Mr. S decide to choose some numbers
from his magic box to multiply to form a perfect square number as a
love present.Undoubtedly, he must pick up one number.

This
week, Mr. S has totally met n numbers a1,a2,...,an. Suddenly, Mr.S come
up with an exciting question that how many different ways of choices
can form a perfect square number as a present. Can you help him solve
it? The answer maybe too large, so you should output the answer modulo
by 1000000007.

Input

First line is a positive integer T (<=5), represents there are T test cases.

For each test case:

First line includes a number n(1≤n≤100000),next line there are n numbers a1,a2,...,an,(1<ai≤10^6).

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 题意:在 n 个整数的质因子的里面选若干个组成完全平方数的种类数?
题解:把各个数分解得到质因子数 ,然后要是完全平方数,那么每种质因子的个数都要是偶数,对于某个质因子假设个数为 x,那么选法就有 C(x,0)+C(x,2)+..+C(x,最接近x的那个偶数) = 2^(x-1) 通过排列组合得解. 答案要减掉全部都不选的那种.
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL mod = ;
const int N = ;
int n;
LL prime[N+];
LL num[N];
void getPrime()
{
memset(prime,,sizeof(prime));
for(int i=; i<=N; i++)
{
if(!prime[i])prime[++prime[]]=i;
for(int j=; j<=prime[]&&prime[j]<=N/i; j++)
{
prime[prime[j]*i]=;
if(i%prime[j]==) break;
}
}
}
LL fatCnt;
void getFactors(LL x)
{
LL tmp=x;
for(int i=; prime[i]<=tmp/prime[i]; i++)
{
if(tmp%prime[i]==)
{
while(tmp%prime[i]==)
{
num[prime[i]]++;
tmp/=prime[i];
}
}
}
if(tmp!=) num[tmp]++;
}
LL pow_mod(LL a,LL n){
LL ans = ;
while(n){
if(n&) ans = ans*a%mod;
a = a*a%mod;
n>>=;
}
return ans;
}
int main()
{
int tcase,t=;
scanf("%d",&tcase);
getPrime();
while(tcase--)
{
memset(num,,sizeof(num));
int n;
scanf("%d",&n);
LL a;
for(int i=; i<n; i++)
{
scanf("%lld",&a);
getFactors(a);
}
LL ans = ;
for(int i=;i<N;i++){
if(num[i]>){
ans = ans*pow_mod(,num[i]-)%mod;
}
}
printf("Case #%d:\n%lld\n",t++,ans-);
}
return ;
}

最新文章

  1. centos7 memcached+memagent 集群
  2. [游戏学习29] Win32 图像处理1
  3. [Linux主机] 优化你的php-fpm(php5.3+)让你的网站跑得更快
  4. sql 数据库查看主外键关联
  5. DataReader反射泛型对象
  6. SB淘宝api的奇葩问题! 一则服务器无法访问淘宝api
  7. Arduino LiquidCrystal Library Bug Report #174181
  8. 重装Win10系统的非常简单的操作教程
  9. JavaScript中的私有成员[翻译]
  10. 使用JDBC中的出现的乱码和查询无结果问题
  11. [NOIP2009][LuoguP1073] 最优贸易 - Tarjan,拓扑+DP
  12. 2018/12/21:Date类
  13. 《生命》第五集:Birds (鸟类)
  14. vim编辑器操作命令
  15. open-falcon部署v0.2.1版本
  16. CENTOS7错误:Cannot find a valid baseurl for repo: base/7/x86_6
  17. 错误:“Cannot load JDBC driver class &#39;com.mysql.jdbc.Driver”的解决方法
  18. Windows下安装Python及Eclipse中配置PyDev插件
  19. &lt;context:component-scan&gt;自动扫描
  20. AES算法工具类

热门文章

  1. linux内核设计与实现第七周读书笔记
  2. spark(一)
  3. 驱动之DMA的介绍与应用20170210
  4. [转载]DataView详解
  5. 树莓派安装python3.5
  6. SSM与SSH的对比
  7. sleep php函数
  8. 查看MySQL日志数据binlog文件
  9. 通过循环判断size()清理queue的问题
  10. Ubuntu 14.04.3 window10双系统情遇到&#39;Disconnected: You are now offline&#39;问题