A1096. Consecutive Factors
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的更多相关文章
- PAT A1096 Consecutive Factors (20 分)——数字遍历
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- PAT甲级——A1096 Consecutive Factors【20】
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- PAT_A1096#Consecutive Factors
Source: PAT A1096 Consecutive Factors (20 分) Description: Among all the factors of a positive intege ...
- 1096. Consecutive Factors (20)
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- PAT1096:Consecutive Factors
1096. Consecutive Factors (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...
- PAT 甲级 1096 Consecutive Factors
https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...
- PAT 1096 Consecutive Factors[难]
1096 Consecutive Factors (20 分) Among all the factors of a positive integer N, there may exist sever ...
- PAT甲级——1096 Consecutive Factors (数学题)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors ...
- 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 ...
随机推荐
- Visual Studio2017 数据库架构比较
一.前言 开发的时候在测试服务器上和线网服务器上面都有我们的数据库,当我们在线网上面修改或者新增一些字段后,线网的数据库也需要更新,这个时候根据表的修改记录,然后在线网上面一个一个增加修改很浪费效率而 ...
- MATLAB找不到遗传算法工具箱,用不了gatool命令的解决方案
解决方案 官方解释如下: gatool was removed as of R2015b. Use optimtool 在MATLAB R2015b前的版本可以使用gatool调用遗传算法工具箱,我测 ...
- websocket(二)——基于node js 的同步聊天应用
https://github.com/sitegui/nodejs-websocket 1.用node搭建本地服务 npm install nodejs-websocket var ws = re ...
- 【SE】Week17 : 软件工程课程总结
软工课程总结 总算结束了一个学期大部分的事情,可以静下心来写篇软工的总结了. 在本学期的软工课程中,我担任的角色是Chronos团队的PM兼开发人员.在课程之前,我认为PM的角色应该还蛮轻松的,无非 ...
- Can't find model 'en'
在使用 nlp = spacy.load("en") 报错OSError: Can't find model 'en' 应该用 python -m spacy download e ...
- C++高质量编程笔记
/* * 函数介绍: * 输入参数: * 输出参数: * 返回值 : */ void Function(float x, float y, float z) { - } if (-) { - whil ...
- 20150409作业3 阅读《构建之法》1-5章 (Update:2015-04-16
以下是我看<构建之法>1-5章列出来的知识点和一些自己对部分知识的理解以及一些吐槽...和感受 1.1 软件 = 程序 + 软件工程 (软件工程 = 软件 - 程序(我知道软件是什么,也知 ...
- HDOJ2032_杨辉三角
这是一道水题,思路很简单,把杨辉三角先求出来,然后按照输入将相应的层数的杨慧三角输出即可. HDOJ2032_杨辉三角 #include<stdio.h> #include<stdl ...
- beanutils的使用
在项目进行中,使用到beanutils时发现1.9.X以上版本搭配logging搭配使用用不了,实在搞不明白.----stackoverflow提问吧 BeanUtils工具由Apache软件基金组织 ...
- Eclipse:An internal error occurred during: "Building workspace". GC overhead limit exceeded
http://blog.csdn.net/shaozhang872196/article/details/18552273 http://www.cnblogs.com/sonofelice/p/52 ...