POJ 3421 X-factor Chains(数论)(筛法)()
来源:互联网 发布:javascript取数组分割 编辑:程序博客网 时间:2024/05/22 06:59
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
23410100
Sample Output
1 11 12 12 24 6
题意:给你一个长度为m的整数序列,即1 = X0, X1, X2, …, Xm = X
这个序列满足条件:Xi < Xi+1 and Xi | Xi+1 where a | b means a perfectly divides into b.每一个是前一个的倍数。(都是X的因子)
让你求最大长度,和最多有多少中这样长度的序列。
思路:首先筛法求素数;然后计算每个不同因子的指数和,即总因子数,就是最大长度了。
然后数量=幂和的阶乘/各个幂阶乘的和
已经AC,心中痛苦啊,因为 const int N = 1100005;//此处的数据要重视,本人wa了n次啊,大于1100005,小于10^7。
#include<iostream>//poj 3421#include<cstdio>#include<cstring>using namespace std;typedef long long ll;const int N = 1100005;//此处的数据要重视,本人wa了n次啊const int M = 10005;int num,n,index;int prime[M],flag[N],sum[M]; //存每个素因子的指数,即个数void Init()//筛法求素数{ for(int i=2;i<=N;i++) { if(flag[i]) continue; prime[num++]=i; for(int j=2;i*j<=N;j++) flag[i*j]=1; }}int main(){ Init(); while(scanf("%d",&n)!=EOF) { index=0;//又一次放错了位置,哭死了 memset(sum,0,sizeof(sum));//初始化 for(int i=0;i<num;i++) { if(n%prime[i]==0)//找到所有因子 { while(n%prime[i]==0) { sum[index]++;//计算每个因子的指数和 n/=prime[i]; } index++;//别放在大括号外面了 } if(n==1) break; } //求所有因子的指数和 ll s=0,ans=1; for(int i=0;i<index;i++) s+=sum[i]; //求 for(ll i=2;i<=s;i++)//次数使用int也可以 ans*=i; for(int i=0;i<index;i++) { for(int j=2;j<=sum[i];j++) { ans/=j; } } printf("%lld %lld\n",s,ans); } return 0;}
- POJ 3421 X-factor Chains(数论)(筛法)()
- POJ 3421 - X-factor Chains(数学)
- POJ 3421 X-factor Chains (约数枚举)
- 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 排列组合
- X-factor Chains (poj 3421 数学排列组合)
- poj 3421 X-factor Chains(分解质因数+组合数学)
- POJ 3421X-factor Chains【分解质因子+组合数学】
- POJ 3421 X-factor Chains 已被翻译
- poj 3421 X-factor Chains(数因子分解)
- poj 3421 X-factor Chains 素数筛选 因子分解
- android wifi断开原因分析
- 博弈(SG函数讲解及其应用)(hdu1848)
- 如何成为全栈增长工程师?
- 页面置换算法(操作系统)
- hdu5691--Sitting in Line(状压DP,2016百度之星Round2A/1002)
- POJ 3421 X-factor Chains(数论)(筛法)()
- 实用知识:生成二维码或条形码
- 计算所词性标注集
- 编码规范-如何定义一个优美的类变量
- python字符串应用举例:判断是否满足标题格式
- 工具类:在一张图片中央添加图片
- Linux环境下Apache ActiveMQ 基本安装
- 【C++专题】static_cast, dynamic_cast, const_cast探讨
- Java 实验6 集合类