X-factor Chains 质因子分解+组合数学

X-factor Chains
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7986 Accepted: 2546

Description
Given a positive integer X, an X-factor chain of length m is a sequence of integers,

1 = X0, X1, X2, …, Xm = X

satisfying

Xi < Xi+1 and Xi | Xi+1 where a | b means a perfectly divides into b.

Now we are interested in the maximum length of X-factor chains and the number of chains of such length.

Input
The input consists of several test cases. Each contains a positive integer X (X ≤ 220).

Output
For each test case, output the maximum length and the number of such X-factors chains.

Sample Input
2
3
4
10
100

Sample Output
1 1
1 1
2 1
2 2
4 6

将一个数分解成若干个素数相乘,因为后面分解出来的素数一定是在前面分解之后分解的,所以自然就大2倍以上。然后问有多少条链,其实就是问将所有因子的全排列有多少种,但是要除去重复因子的全排列。
n个不同的数的全排列就是n!,除去重复的就是n!除以每个重复因子数的阶乘。
注:防止爆掉都用的long long 存储


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
const int N=22;
ll fac[N+1]={1};
void init(){
	for(ll i=1;i<=N;i++){
		fac[i]=fac[i-1]*i;
	}
}
int main(){
	init();
	ll n;
	while(cin>>n){
		ll sum=0,d=1;
		for(ll i=2;i*i<=n;i++){
			if(n%i==0){
				ll cnt=0;
				while(n%i==0){
					n/=i;
					cnt++;
				}
				sum+=cnt;
				d*=fac[cnt];
			}
		}
		if(n>1) sum++;
		cout<<sum<<" "<<fac[sum]/d<<endl;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值