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 ...
随机推荐
- Mysql8.0的登录大坑……(忘记登录密码也可以这么搞)
关于安装和使用就不说了,属于基本操作了: 我来重点记录一下关于使用前,使用navicat登录的时候报错,1130和2059 查看安装后随机生成的密码: grep 'temporary password ...
- Mongo 开发笔记
时间 程序的时间是本地时间 ,数据库中的时间是 ISO 标准时间 . ISO时间 + 8 小时 = 本地时间(北京时间 ) Java驱动会自动做转化. 语法 数组查询 数据查询使用 elemMatch ...
- HTML 5 拖放
拖放(Drag 和 drop)是 HTML5 标准的组成部分. 拖放 拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放. 拖放事件 1. ...
- Python-dict-12
字典 Why:咱们目前已经学习到的容器型数据类型只有list,那么list够用?他有什么缺点呢? 1. 列表可以存储大量的数据类型,但是如果数据量大的话,他的查询速度比较慢. 2. 列表只能按照顺序存 ...
- sheet制作返回按钮
=HYPERLINK("#目录!A1","目录!A1") =HYPERLINK("#"&A2&"!A1" ...
- “耐撕团队”部署并测试onezero团队记帐本项目
耐撕团队 对onezero团队记帐本项目的部署并测试 测试指标参见下面给出的博客: http://www.ltesting.net/ceshi/ceshijishu/xncs/2014/1030/20 ...
- jsp中获取不到servlet的cookie
今天做登陆,发现jsp中使用document.cookie获取不到servlet生成的cookie,我们可以在浏览器的cookie文件夹中发现,servlet中生成的cookie和jsp中的生成的路径 ...
- git学习心得
https://github.com/zhangxinn/test/tree/master 自己虽然在课堂上有认真的听老师讲解如何使用github,包括怎样在线学习,怎样在github上建立自己的仓库 ...
- T-shirt 0 0....
老师给我这件T-shirt的目的是为了让我减肥吗...... 听说了pbb的事迹好感动 //偷偷吐槽一句,那个全套吉米多维奇可以报销吗...我就看了2行........ 吓得我赶紧看了一下浴盆的气球
- PAT L3-021 神坛
https://pintia.cn/problem-sets/994805046380707840/problems/994805046577840128 在古老的迈瑞城,巍然屹立着 n 块神石.长老 ...