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 ;
}

csu 1801(合数分解+排列组合)的更多相关文章

  1. POj3421 X-factor Chains(质因数分解+排列组合)

    POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...

  2. LightOJ 1028 - Trailing Zeroes (I) 质因数分解/排列组合

    题意:10000组数据 问一个数n[1,1e12] 在k进制下有末尾0的k的个数. 思路:题意很明显,就是求n的因子个数,本来想直接预处理欧拉函数,然后拿它减n就行了.但注意是1e12次方法不可行.而 ...

  3. hdu 4497 GCD and LCM 质因素分解+排列组合or容斥原理

    //昨天把一个i写成1了 然后挂了一下午 首先进行质因数分解g=a1^b1+a2^b2...... l=a1^b1'+a2^b2'.......,然后判断两种不可行情况:1,g的分解式中有l的分解式中 ...

  4. HDU 4497 GCD and LCM(分解质因子+排列组合)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 题意:已知GCD(x, y, z) = G,LCM(x, y, z) = L.告诉你G.L,求满 ...

  5. hdu_4497GCD and LCM(合数分解)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 GCD and LCM Time Limit: 2000/1000 MS (Java/Other ...

  6. 2018.10.26 poj3421X-factor Chains(数论+排列组合)

    传送门 排列组合入门题. 令X=p1a1p2a2..pkakX=p_1^{a_1}p_2^{a_2}..p_k^{a_k}X=p1a1​​p2a2​​..pkak​​ 那么答案1就等于∑i=1kai\ ...

  7. ACM~排列组合&amp;&amp;hdu例子

    排列组合是数学中的一个分支.在计算机编程方面也有非常多的应用,主要有排列公式和组合公式.错排公式.母函数.Catalan Number(卡特兰数)等. 一.有关组合数学的公式 1.排列公式   P(n ...

  8. 【专题】计数问题(排列组合,容斥原理,Prufer序列)

    [容斥原理] 对于统计指定排列方案数的问题,一个方案是空间中的一个元素. 定义集合x是满足排列中第x个数的限定条件的方案集合,设排列长度为S,则一共S个集合. 容斥原理的本质是考虑[集合交 或 集合交 ...

  9. 【BZOJ】4555: [Tjoi2016&Heoi2016]求和 排列组合+多项式求逆 或 斯特林数+NTT

    [题意]给定n,求Σi=0~nΣj=1~i s(i,j)*2^j*j!,n<=10^5. [算法]生成函数+排列组合+多项式求逆 [题解]参考: [BZOJ4555][Tjoi2016& ...

随机推荐

  1. 【bzoj3170】[Tjoi2013]松鼠聚会

    3170: [Tjoi2013]松鼠聚会 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1670  Solved: 885[Submit][Statu ...

  2. 【bzoj3567】江南乐

    Portal -->bzoj3567 Solution ​  今天开始啃博弈论了qwq ​  先mark一篇很棒的博客Portal -->博弈论学习资料 ​​  稍微总结一下两个自己容易混 ...

  3. 洛谷P3048 [USACO12FEB]牛的IDCow IDs

    P3048 [USACO12FEB]牛的IDCow IDs 12通过 67提交 题目提供者lin_toto 标签USACO2012 难度普及/提高- 时空限制1s / 128MB 提交  讨论  题解 ...

  4. git untrack file

    git update-index should do what you want This will tell git you want to start ignoring the changes t ...

  5. linux命令df中df -h和df -i的区别

    df 命令: linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 1.命令格式: df [选项] [ ...

  6. 基于 Express+Gulp+BrowserSync 搭建一套高性能的前端开发环境

    基于 Express+Gulp+BrowserSync 搭建一套高性能的前端开发环境 Express 是比较经典的,也是最常用的 Nodejs Web框架. 一.Express 快速构建一个web应用 ...

  7. marquee滚动效果

    转载两篇文章: http://blog.sina.com.cn/s/blog_49ce67fc0100atb4.html https://baike.1688.com/doc/view-d359560 ...

  8. a 标签传值

    转载:http://blog.csdn.net/muyeju/article/details/48594377 .<a>标签传值的形式--参数固定:<a href="地址? ...

  9. phpStudy 虚拟主机

    转载:http://blog.csdn.net/sinat_35861664/article/details/53557574 windows下配置虚拟主机,实现多域名访问本地项目目录 1.Apach ...

  10. 用C++写一个没人用的ECS

    github地址:https://github.com/yangrc1234/Resecs 在做大作业的时候自己实现了一个简单的ECS,起了个名字叫Resecs. 这里提一下一些实现的细节,作为回顾. ...