题意:一条整数链,要求相邻两数前一个整除后一个。给出链尾的数,求链的最大长度以及满足最大长度的不同链的数量。

类型:因式分解+排列组合

算法:因式分解的素因子个数即为链长,链中后一个数等于前一个数乘以某素因子,所以链的数量即为这些因子不全相异的全排列数:A!/(a1!a2!a3!..)

#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std; typedef long long LL;
int p[22], a[22];
int cnt; int main() {
int n, i, j;
while (scanf("%d", &n) != EOF) {
cnt = 0;
for (i = 2; i <= sqrt(n); ++i) { // 质因子分解
if (n % i == 0) {
p[cnt] = i;
n /= i;
a[cnt++] = 1;
}
while (n % i == 0) {
a[cnt - 1]++;
n /= i;
}
}
if (n > 1) { // 注意点,容易忘记
p[cnt] = n;
a[cnt++] = 1;
}
LL ans = 1;
int A = 0;
for (i = 0; i < cnt; ++i) {
A += a[i];
}
for (i = a[0] + 1; i <= A; ++i) { // 提前除以a[0]!
ans *= i;
}
for (i = 1; i < cnt; ++i) {
for (j = 2; j <= a[i]; ++j) {
ans /= j;
}
}
printf("%d %lld\n", A, ans);
}
return 0;
}

最新文章

  1. [LeetCode] Integer to Roman 整数转化成罗马数字
  2. beaglebone black 烧写系统后释放空间。
  3. 设计模式-观察者模式(Observer Model)
  4. C语言中的参数传递
  5. IsBackground的理解
  6. ubuntu Screen 的比较详细的命令
  7. maven pom.xml报错
  8. java字符串练习题
  9. [ActionScript 3.0] AS3 对XML的操作,创建、删除、增加节点方法
  10. HDU4612 Warm up 边双连通分量&amp;&amp;桥&amp;&amp;树直径
  11. springside springmvc 的一个SB问题
  12. [转]Ubuntu 软件安装、查找、卸载--apt-get、apt-cache命令安全
  13. Windows下PHP(Thread Safe与Non Thread Safe)版本说明
  14. accp8.0转换教材第9章JQuery相关知识理解与练习
  15. angular2 实现的小项目
  16. Open-Source Service Discovery
  17. android 开发中 sdk 无法更新
  18. Autodesk系列软件下载
  19. JS 通过字符串取得对应对象
  20. Flume和Kafka整合安装

热门文章

  1. Spring面向切面编程AOP(around)实战
  2. VUE2.0 饿了吗视频学习笔记(三):VUE2.0取消了v-link
  3. 序列化时提示There was an error reflecting type &#39;System.Collections.Generic.List`1
  4. Host is not allowed to connect to this MySQL server解决方法
  5. js 获取DOM的style属性
  6. Linux - vim 编辑器
  7. div 只显示两行超出部分隐藏
  8. HDU 2522 A simple problem (模拟)
  9. react框架实现点击事件计数小案例
  10. VGG 参数分析 转