poj 3421 X-factor Chains
2014-07-27 09:21
567 查看
X-factor Chains
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
Sample Output
Source
POJ Monthly--2007.10.06, ailyanlu@zsu
分解质因数,然后求一个组合数就成。
s=p1^a1*p2^a2*p3^a3.....pn^an
组合数为:(a1+a2...an)!/(a1!*a2!...*an!)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5326 | Accepted: 1683 |
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
Source
POJ Monthly--2007.10.06, ailyanlu@zsu
分解质因数,然后求一个组合数就成。
s=p1^a1*p2^a2*p3^a3.....pn^an
组合数为:(a1+a2...an)!/(a1!*a2!...*an!)
/* Problem: 3421 User: motefly Memory: 3040K Time: 344MS Language: G++ Result: Accepted */ #include <iostream> #include <cstdio> #include <cmath> using namespace std; const int maxn=1048600; int prime[maxn+5]; bool is_prime[maxn+6]; bool hash[maxn+5]; #define ll long long int sieve(int n) { int p=0; for(int i=0;i<=n;i++) is_prime[i]=true; is_prime[0]=is_prime[1]=0; for(int i=2;i<=n;i++) { if(is_prime[i]) { prime[p++]=i; hash[i]=1; for(int j=2*i;j<=n;j+=i) is_prime[j]=0; } } hash[1]=1; return p; } ll f[21]; int a[21]; void init() { sieve(maxn); f[1]=1; for(int i=2;i<=20;i++) f[i]=f[i-1]*i; } int main() { init(); ll n; while(~scanf("%lld",&n)){ int k=0; if(hash ==1) { printf("1 1\n"); continue; } for(int i=0;prime[i]<=n;i++) { if(n==1) break; a[k]=0; if(n%prime[i]==0) { while(n%prime[i]==0) { n/=prime[i]; a[k]++; } k++; } } int sum1=0; ll sum2=1; for(int i=0;i<k;i++) { sum1+=a[i]; sum2*=f[a[i]]; } printf("%d %lld\n",sum1,f[sum1]/sum2); } }
相关文章推荐
- Poj 3421-X-factor Chains
- POJ 3421 X-factor Chains(数论)(筛法)()
- [poj] 3421 X-factor Chains
- 数论·GCD---POJ 3421-X-factor Chains
- POJ-3421-X-factor Chains
- 【POJ】3421 - X-factor Chains 素数
- Mathematics:X-factor Chains(POJ 3421)
- 码农场 » POJ 3421 X-factor Chains 题解 《挑战程序设计竞赛》
- POJ 3421 - X-factor Chains(数学)
- POJ 3421 X-factor Chains(构造)
- POJ 3421 X-factor Chains (因式分解+排列组合)
- poj 3421 --X-factor Chains(数学、组合)
- POJ_3421_X-factor Chains(素数筛法)
- POJ 3421 X-factor Chains 笔记
- POJ 3421 X-factor Chains 题解 《挑战程序设计竞赛》
- POJ 3421 X-factor Chains(dp or 素因子分解)
- poj 3421 X-factor Chains(分解质因数+组合数学)
- POJ 3421 X-factor Chains【分解质因子+组合数学】
- POJ 3421 X-factor Chains (整数分解+组合数)
- POJ 3421 X-factor Chains | 数论