csu 1801(合数分解+排列组合)
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(合数分解+排列组合)的更多相关文章
- POj3421 X-factor Chains(质因数分解+排列组合)
POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...
- LightOJ 1028 - Trailing Zeroes (I) 质因数分解/排列组合
题意:10000组数据 问一个数n[1,1e12] 在k进制下有末尾0的k的个数. 思路:题意很明显,就是求n的因子个数,本来想直接预处理欧拉函数,然后拿它减n就行了.但注意是1e12次方法不可行.而 ...
- hdu 4497 GCD and LCM 质因素分解+排列组合or容斥原理
//昨天把一个i写成1了 然后挂了一下午 首先进行质因数分解g=a1^b1+a2^b2...... l=a1^b1'+a2^b2'.......,然后判断两种不可行情况:1,g的分解式中有l的分解式中 ...
- 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,求满 ...
- hdu_4497GCD and LCM(合数分解)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 GCD and LCM Time Limit: 2000/1000 MS (Java/Other ...
- 2018.10.26 poj3421X-factor Chains(数论+排列组合)
传送门 排列组合入门题. 令X=p1a1p2a2..pkakX=p_1^{a_1}p_2^{a_2}..p_k^{a_k}X=p1a1p2a2..pkak 那么答案1就等于∑i=1kai\ ...
- ACM~排列组合&&hdu例子
排列组合是数学中的一个分支.在计算机编程方面也有非常多的应用,主要有排列公式和组合公式.错排公式.母函数.Catalan Number(卡特兰数)等. 一.有关组合数学的公式 1.排列公式 P(n ...
- 【专题】计数问题(排列组合,容斥原理,Prufer序列)
[容斥原理] 对于统计指定排列方案数的问题,一个方案是空间中的一个元素. 定义集合x是满足排列中第x个数的限定条件的方案集合,设排列长度为S,则一共S个集合. 容斥原理的本质是考虑[集合交 或 集合交 ...
- 【BZOJ】4555: [Tjoi2016&Heoi2016]求和 排列组合+多项式求逆 或 斯特林数+NTT
[题意]给定n,求Σi=0~nΣj=1~i s(i,j)*2^j*j!,n<=10^5. [算法]生成函数+排列组合+多项式求逆 [题解]参考: [BZOJ4555][Tjoi2016& ...
随机推荐
- BZOJ5314 [Jsoi2018]潜入行动 【背包类树形dp】
题目链接 BZOJ5314 题解 设\(f[i][j][0|1][0|1]\)表示\(i\)为根的子树,用了\(j\)个监测器,\(i\)节点是否被控制,\(i\)节点是否放置的方案数 然后转移即可 ...
- 很好的c++和Python混合编程文章
c++中嵌入python入门1 本人是用vc2003+python2.5学习的,其它的也应该差不了多少 0. 坏境设置把Python的include/libs目录分别加到vc的include/lib ...
- Codeforces Round #207 (Div. 2)A B C E 水 思路 set 恶心分类
A. Group of Students time limit per test 1 second memory limit per test 256 megabytes input standard ...
- unity直连android真机在Profiler性能分析测试
基础步骤: 1.Unity打开你要测试的项目:File–Build Settings 2.如下图,按图顺序进行1.2.3.4.5操作,如果做过了,2就是灰色的,不能被点击,4和5需要相对应. 3.确保 ...
- discuz uc_server 配置登录
新运行uc_server环境,先配置好ucenter链接-----这部很重要,我从新环境中安装下载的discuz代码,这部没配置,密码又不知道,怎么更改调试,都不起作用,在框架中,跳转到了原来线上的u ...
- mysql5.7中root密码忘记后修改密码
一.更改my.cnf配置文件 1.用命令编辑/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnf 2.在[mysqld]下添加skip-grant-t ...
- ORACLE创建用户,建表空间,授予权限
1.创建用户表空间 CREATE TABLESPACE my_tsLOGGINGDATAFILE 'D:\app\win7\oradata\orcl\my_ts.dbf' SIZE 10M AUTOE ...
- [DeeplearningAI笔记]序列模型1.1-1.2序列模型及其数学符号定义
5.1循环序列模型 觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.1什么是序列模型 在进行语音识别时,给定了一个输入音频片段X,并要求输出片段对应的文字记录Y,这个例子中的输入和输出都输 ...
- tf.train.batch的偶尔乱序问题
tf.train.batch的偶尔乱序问题 觉得有用的话,欢迎一起讨论相互学习~Follow Me tf.train.batch的偶尔乱序问题 我们在通过tf.Reader读取文件后,都需要用batc ...
- Latent Semantic Analysis(LSA/ LSI)原理简介
LSA的工作原理: How Latent Semantic Analysis Works LSA被广泛用于文献检索,文本分类,垃圾邮件过滤,语言识别,模式检索以及文章评估自动化等场景. LSA其中一个 ...