Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maximum number of consecutive factors, and list the smallest sequence of the consecutive factors.

Input Specification:

Each input file contains one test case, which gives the integer N (1<N<231).

Output Specification:

For each test case, print in the first line the maximum number of consecutive factors. Then in the second line, print the smallest sequence of the consecutive factors in the format "factor[1]*factor[2]*...*factor[k]", where the factors are listed in increasing order, and 1 is NOT included.

Sample Input:

630

Sample Output:

3
5*6*7
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
int N, sqr, maxLen = -, index;
long long P;
scanf("%d", &N);
sqr = (int)sqrt(N * 1.0);
for(int i = ; i <= sqr + ; i++){
int j = i;
P = ;
while(){
P *= j;
if(P < )
break;
if(N % P != )
break;
if(j - i + > maxLen){
maxLen = j - i + ;
index = i;
}
j++;
}
}
if(maxLen != -){
printf("%d\n", maxLen);
printf("%d", index++);
}else{
printf("%d\n%d", , N);
}
for(int i = ; i < maxLen; i++){
printf("*%d", index++);
}
cin >> N;
return ;
}

总结:

1、测试630的序列,应该是测试 630 / 3, 630 /(3 * 4), 630 / (3 * 4 * 5),而非测试630 / 3,630 / 4, 630 / 5。

2、 考虑到无解的可能,比如素数13, index 与maxlen没有进入循环,应单独输出。

3、有可能sqrt(N)后有误差,应该判断到 sqrt(N + 1)而非 sqrt(N)。

4、只要有累乘,就应该用long long,并且考虑到溢出为负的可能。

A1096. Consecutive Factors的更多相关文章

  1. PAT A1096 Consecutive Factors (20 分)——数字遍历

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  2. PAT甲级——A1096 Consecutive Factors【20】

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  3. PAT_A1096#Consecutive Factors

    Source: PAT A1096 Consecutive Factors (20 分) Description: Among all the factors of a positive intege ...

  4. 1096. Consecutive Factors (20)

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  5. PAT1096:Consecutive Factors

    1096. Consecutive Factors (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  6. PAT 甲级 1096 Consecutive Factors

    https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...

  7. PAT 1096 Consecutive Factors[难]

    1096 Consecutive Factors (20 分) Among all the factors of a positive integer N, there may exist sever ...

  8. PAT甲级——1096 Consecutive Factors (数学题)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors  ...

  9. PAT (Advanced Level) Practise - 1096. Consecutive Factors (20)

    http://www.patest.cn/contests/pat-a-practise/1096 Among all the factors of a positive integer N, the ...

随机推荐

  1. Android 安全退出应用程序的方法总结

    正常关闭应用程序: 当应用不再使用时,通常需要关闭应用,可以使用以下三种方法关闭android应用: 第一种方法:首先获取当前进程的id,然后杀死该进程. android.os.Process.kil ...

  2. Python_试题_23

    # Python基础数据类型考试题# 考试时间:两个半小时 满分100分(80分以上包含80分及格)# 一,基础题.# 1,简述变量命名规范(3分)# 答:变量名是由数字.字母.下划线任意组合,变量名 ...

  3. 【SE】Week17 : 软件工程课程总结

    软工课程总结  总算结束了一个学期大部分的事情,可以静下心来写篇软工的总结了. 在本学期的软工课程中,我担任的角色是Chronos团队的PM兼开发人员.在课程之前,我认为PM的角色应该还蛮轻松的,无非 ...

  4. UML类图及类与类之间的关系

    原文地址:http://www.uml.org.cn/oobject/201211231.asp 类图用于描述系统中所包含的类以及它们之间的相互关系,帮助人们简化对系统的理解,它是系统分析和设计阶段的 ...

  5. hibernate ehcache二级缓存

    xml配置 <?xml version="1.0" encoding="UTF-8"?> <ehcache> <!-- Sets ...

  6. github个人心得和链接

    github使用心得: 在本次github使用过程中,我总结了git常用命令,都有哪些功能? git常用命令: git config :配置git git add:更新working director ...

  7. 09-java学习-数组-冒泡排序-选择排序-数组工具类编写-查找-扩容

    数组的排序算法 查找算法 数组协助类Arrays的学习和使用 数组的扩容

  8. tftp服务、串口工具minicom

    linux下安装tftp服务 参考这位仁兄的经验 确实百度上很多关于配置tftp服务的方法,但是这篇文章的介绍真的是很精简,对于一个刚接触纯linux环境的小白来说是很舒服的一件事. 首先是安装tft ...

  9. Windows 版本下 Oracle12.1.0.2 升级Oracle12.2.0.1的步骤

    oracle12.1.0.1 2013年发布的产品 2014年左右发布12.1.0.2 2016年底发布了 oracle12.2.0.1 经常有人会安装了最早的oracle版本,然后需要升级到最新的o ...

  10. Python模块笔记

    __name__属性 一个模块被另一个程序第一次引入时,其主程序将运行.如果我们想在模块被引入时,模块中的某一程序块不执行,我们可以用__name__属性来使该程序块仅在该模块自身运行时执行. #!/ ...