POJ 3421X-factor Chains【分解质因子+组合数学】
来源:互联网 发布:gta5精简优化版 编辑:程序博客网 时间:2024/05/23 15:10
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
Source
题意:
给出一个数字 n ,问 n 的因子组成的满足任意前一项都能整除后一项的序列的最大长度,以及所有不同序列的个数
题解:
最直观的考虑肯定是第一位是1,随后的数进行讨论
不难发现,按题目要求的话要求序列最长,那么就要尽量使得临近的数的比值尽量小,有个理论说(忘了哪个伟人说的了),任意一个比较大的合数,都能写成若干个素数的积,也就是说,肯定能找到某个数的一个非常小的不可分割的单位(最小素因子?)。
尝试如下:
给出一个数n,那么首先找到这个数最小的素因子x,作为序列的第二个元素,然后,假如,这个x*x 依然能被n 整除,那么x*x 此时肯定是能满足题意要求的最小值,依次判断x*x*x....一直到不满足题意,但是还没完.....不一定能完全除尽,那就要考虑次大的素因子了,继续像这样一直尝试,如果最终未除尽,剩余的部分也要算上,因为这个部分乘上倒数第二项,肯定是n,也就是仍然满足题意的!
表达能力有点水,上实例:
100
1,首项 1,没什么说的
2,为了尽量长,用最小的素数(2)去分割,得到2*2*25,那么就是说,另外可以构造出两项了 2,2*2(4)
3,发现不能整除了,那么寻找100的次小的素因子,找到5,把剩下的25 分解成5*5,那么就可以再构造出两项 2*2*5(20),2*2*5*5(100)
那么最后的结果就是1,2,4,20,100,按题意,最长的可能是 4
对于6怎么来的,组合数学有一条说:
n个物体一共有k 个,m种,其中每一种对应n1,n2,n3,n4....个,那么这些物品全排列的总数目是:
n!/(n1+n2+....+nm)!
个人也不懂,怎么推出来的.....
(以上纯属个人理解,错误之处指出还请大神不吝指出)
/*http://blog.csdn.net/liuke19950717*/#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;int main(){ll x[25]={1};for(ll i=1;i<25;++i){x[i]=i*x[i-1];}ll n;while(~scanf("%lld",&n)){ll ans=0,base=1;for(ll i=2;i*i<=n;++i){if(n%i==0){ll cnt=0;while(n%i==0){++cnt;n/=i;}ans+=cnt;base*=x[cnt];}}if(n>1){ans+=1;}printf("%lld %lld\n",ans,x[ans]/base);}return 0;}
- POJ 3421X-factor Chains【分解质因子+组合数学】
- POJ3421 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 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 排列组合
- POJ3421 X-factor Chains 数学
- POJ 3421 X-factor Chains (约数枚举)
- Java 将15位身份证号转化为18位返回,非15位身份证号原值返回
- javascript去除字符串左右两端的空格
- 215. Kth Largest Element in an Array
- mac下安装brew遇到的问题总结
- 类目和延展的作用和区别?
- POJ 3421X-factor Chains【分解质因子+组合数学】
- 3D Touch
- 总结一下java中的位操作,运算优先级
- ApachePOI导出exce,设置单元格风格的属性和设置字体风格的属性的两个工具类,POI宽度和excel 像素转换
- 如何求两个矩形相交面积
- 查找--静态查找与动态查找
- MTK之UART串口收发数据
- SDAU练习二1011
- 不用导入SDK就可实现导航--URI方式跳转到各类地图进行导航