poj3421 X-factor Chains——分解质因数
题目:http://poj.org/problem?id=3421
好久没有独立A题了...做点水题还是有助于提升自信心的;
这题就是把 x 质因数分解,质因数指数的和 sum 就是最长的长度,因为每次至少乘一个质因数;
排列方式就是从 sum 个位置里给第一种质因数选几个位置,再在剩下的里面给第二种质因数选几个位置...
也就是 ans = ∏(1<=i<=cnt) C(n,pc[i]),n -= pc[i],其中 cnt 是质因数(种类)个数,pc 是每种质因数的指数,n 就是目前剩下几个位置。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int x,p[],pc[],cnt;
void divide(int n)
{
cnt=;
memset(pc,,sizeof pc);
for(int i=;i*i<=n;i++)
if(n%i==)
{
p[++cnt]=i;
while(n%i==)pc[cnt]++,n/=i;
}
if(n>)p[++cnt]=n,pc[cnt]=;
}
ll C(int n,int m)
{
if(n<m)return ;
m=min(m,n-m);
ll a=,b=;
for(int i=n-m+;i<=n;i++)a*=i;
for(int i=;i<=m;i++)b*=i;
return a/b;
}
int main()
{
while(~scanf("%d",&x))
{
divide(x);
int sum=; ll ans=;
for(int i=;i<=cnt;i++)sum+=pc[i];
int n=sum;
for(int i=;i<=cnt;i++)
{
ans*=C(n,pc[i]);
n-=pc[i];
}
printf("%d %lld\n",sum,ans);
}
return ;
}
poj3421 X-factor Chains——分解质因数的更多相关文章
- hdu 5428 The Factor 分解质因数
The Factor Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/contest ...
- light oj 1236 分解质因数
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/H 题意:求满足1<=i<=j<=n ...
- The largest prime factor(最大质因数)
1. 问题: The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number ...
- POJ1811(SummerTrainingDay04-G miller-rabin判断素性 && pollard-rho分解质因数)
Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 35528 Accepted: 9479 Case ...
- HDU 5428 分解质因数
The F ...
- java分解质因数
package test; import java.util.Scanner; public class Test19 { /** * 分析:对n进行分解质因数,应先找到一个最小的质数k * 最小 ...
- 程序设计入门——C语言 第6周编程练习 1 分解质因数(5分)
1 分解质因数(5分) 题目内容: 每个非素数(合数)都可以写成几个素数(也可称为质数)相乘的形式,这几个素数就都叫做这个合数的质因数.比如,6可以被分解为2x3,而24可以被分解为2x2x2x3. ...
- 【python】将一个正整数分解质因数
def reduceNum(n): '''题目:将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5''' print '{} = '.format(n), : print 'Pleas ...
- 【基础数学】质数,约数,分解质因数,GCD,LCM
1.质数: 质数(prime number)又称素数,有无限个.一个大于1的自然数,除了1和它本身外,不能整除以其他自然数(质数),换句话说就是该数除了1和它本身以外不再有其他的因数. 2.约数: 如 ...
随机推荐
- Redis系列(十)--集群cluster
在之前学习了Master-Slave.Sentinel模式,但是在某些情况下还是无法满足系统对QPS等要求,这时候就需要Cluster,Redis3.0支持了cluster 一.为什么使用Cluste ...
- spring用来干什么,解决的问题
// 1. 实体类 class User{ } //2. dao class UserDao{ .. 访问db } //3. service class UserService{ UserDao ...
- 编译器:gcc, clang, llvm
clang Clang是LLVM的前端,可以用来编译C,C++,ObjectiveC等语言.传统的编译器通常分为三个部分,前端(frontEnd),优化器(Optimizer)和后端(backEnd) ...
- 「 HDU P2089 」 不要62
和 HDOJ 3555 一样啊,只不过需要多判断个 ‘4’ 我有写 3555 直接去看那篇吧 这里只放代码 #include <iostream> #include <cstring ...
- [USACO] 奶牛混合起来 Mixed Up Cows
题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...
- MyBatis 的基本要素—核心对象
MyBatis 三个基本要素 ➢ 核心接口和类 ➢ MyBatis 核心配置文件(mybatis-config.xml) ➢ SQL 映射文件(mapper.xml) MyBatis 核心接口和类 ...
- Diango REST framework 视图继承图
- 网络基础——TCP
TCP和UDP协议特点 1.TCP 1>.传输控制协议 2>.可靠的.面向连接的协议 3>.传输效率低 2.UDP 1>.用户数据报协议 2>.不可靠的.无连接的服务 3 ...
- reshape column vector data in Matlab
input: import data 2. transpose the data 3. reshape the data into array code: matlab load x.dat X=x ...
- 2.5.5.2 特殊文件:/dev/null 与 /dev/tty
UNIX 系统提供了两个对Shell编程特别有用的特殊文件. 第一个文件 /dev/null ,就是大家所熟知的位桶(bit bucket).传送到此文件的数据都会被丢掉.换句话说 ...