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& ...
随机推荐
- 阿里云ECS环境部署 centos 6.5
阿里云ESC服务器1 先挂载磁盘 参考:http://help.aliyun.com/view/11108189_13491193.html?spm=5176.2020520101.121.2.1wc ...
- 关于JBoss基本说明文档及基本使用安装
关于JBoss JBoss是全世界开发者共同努力的成果,一个基于J2EE的开放源代码的应用服务器.在不 到12个月的时间里有一百万以上的拷贝被下载.JBoss是第一位的J2EE应用服务器. J ...
- (二)SMO算法
11 SMO优化算法(Sequential minimal optimization) SMO算法由Microsoft Research的John C. Platt在1998年提出,并成为最快的二次规 ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) F dfs序+树状数组
Performance ReviewEmployee performance reviews are a necessary evil in any company. In a performance ...
- 1.UiDevice API 详细介绍
1.UiDevice按键与keycode使用 返回值 方法名 说明 boolean pressBack() 模拟短按返回back键 boolean pressDPadCenter() 模拟按轨迹球中点 ...
- 前端PHP入门-013-变量作用域
目前,我们知道了几个不同的规矩: 函数定义时后括号里面接的变量是形式上的参数(形参),与函数体外的变量没有任何关系.仅仅是在函数内部执行 函数内声明的变量也与函数外的变量没关系. 但是,我们实际的处理 ...
- redis服务启动脚本
/etc/rc.d/init.d/redis #!/bin/sh# chkconfig: 2345 80 90 # description: Start and Stop redis REDISPOR ...
- zTree使用技巧与详解
zTree--Jquery 树插件,是在后台管理页面中常使用到的插件. 使用效果图: 核心代码: zTree配置: var setting = { data:{simpleData:{enable:t ...
- UVA 1650 Number String
https://vjudge.net/problem/UVA-1650 题意:D表示比前一个数打,I表示比前一个数小,?表示不确定 给出一个长为n由D I?组成的字符串,问满足字符串大小要求的n+1的 ...
- 2-sat基础题 uvalive 3211
蓝书325页的基础题 二分+2-sat //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include <bits/stdc++.h> using n ...