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. mysql三-1:存储引擎

    一 什么是存储引擎 mysql中建立的库===>文件夹 库中建立的表===>文件 现实生活中我们用来存储数据的文件有不同的类型,每种文件类型对应各自不同的处理机制:比如处理文本用txt类型 ...

  2. hiho 1044 : 状态压缩

    #1044 : 状态压缩·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在兑换到了喜欢的奖品之后,便继续起了他们的美国之行,思来想去,他们决定乘坐火车 ...

  3. 洛谷P1396 营救

    题目描述 “咚咚咚……”“查水表!”原来是查水表来了,现在哪里找这么热心上门的查表员啊!小明感动的热泪盈眶,开起了门…… 妈妈下班回家,街坊邻居说小明被一群陌生人强行押上了警车!妈妈丰富的经验告诉她小 ...

  4. lightoj 1020 (博弈水题)

    lightoj 1020 A Childhood Game 链接:http://lightoj.com/volume_showproblem.php?problem=1020 题意:一堆石子有 m 个 ...

  5. sql like参数化查询

    如下例所示,这样做了后再也不担心sql注入了.... public static DataTable GetProPriEEfocusNew(string ProName) { StringBuild ...

  6. tomcat maven插件启动报错tomcat-users.xml cannot be read

    tomcat maven插件启动报错tomcat-users.xml cannot be read [ERROR] Failed to execute goal org.codehaus.mojo:t ...

  7. Android图片压缩工具MCompressor

    这是一个简单的图片压缩工具(MCompressor),可自定义压缩的格式和质量,以及压缩后存储的文件路径,可决定对多大的文件进行压缩. 使用方法 build.gradle文件 Step 1. Add ...

  8. background(css复合写法)

    1. 背景-background========================================================== 单个属性的写法 .sample1 { /*背景颜色 ...

  9. HDU6128 二次剩余/二次域求二次剩余解/LL快速乘法取模

    LINK 题意:求满足模p下$\frac{1}{a_i+a_j}\equiv\frac{1}{a_i}+\frac{1}{a_j}$的对数,其中$n,p(1\leq n\leq10^5,2\leq p ...

  10. javascript小技巧之with()方法

    With()方法平时用得不多,本文用个小例子来学习一下.在这里记录.个人感觉还是很方便的. 有了 With 语句,在存取对象属性和方法时就不用重复指定参考对象,在 With 语句块中,凡是 JavaS ...