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. Mybatis中 collection 和 association 的区别?

    public class A{ private B b1; private List<B> b2;} 在映射b1属性时用association标签,(一对一的关系) 映射b2时用colle ...

  2. 容斥原理I

    普利斯记号 以下以"人"代指受条件约束的元素. \(K(x)\)表示刚好\(x\)人满足条件的方案数. \(S(x)\)表示至少\(x\)人满足条件的方案数. \(C(x)\)表示 ...

  3. A. Vasya and Chocolate

    链接 [http://codeforces.com/contest/1065/problem/A] 分析 一个公式完事 代码 #include<bits/stdc++.h> using n ...

  4. D. Little C Loves 3 II

    传送门 [http://codeforces.com/contest/1047/problem/D] 题意 给你n*m得棋盘,让你找两点之间距离为3的点的个数,不能重复使用,距离定义,两坐标差绝对值之 ...

  5. Python学习笔记 ---第三章

    函数 函数是代码的一种抽象 函数 说明 abs 绝对值 max 最大值 hex 转换为16进制 强制数据类型转换 int('123') 123 int(12.35) 12 srt(100) '100' ...

  6. 圆桌的项目Alpha冲刺(团队)

    (a) 项目课堂演示 (b) 10篇冲刺随笔 冲刺之一 冲刺之二 冲刺之三 冲刺之四 冲刺之五 冲刺之六 冲刺之七 冲刺之八 冲刺之⑨ 冲刺之十 (c) 1篇测试随笔 测试随笔 (d) 1篇冲刺总结随 ...

  7. PAT 1007 素数对猜想

    https://pintia.cn/problem-sets/994805260223102976/problems/994805317546655744 让我们定义 d~n~ 为:d~n~ = p~ ...

  8. shell 学习笔记二

    一.break命令 break命令允许跳出所有循环(终止执行后面的所有循环). 下面的例子中,脚本进入死循环直至用户输入数字大于5.要跳出这个循环,返回到shell提示符下,就要使用break命令. ...

  9. 线性代数的本质与几何意义 02. 线性组合、张成的空间、基(3blue1brown 咪博士 图文注解版)

    1. 线性组合 接下来我们要换一个角度来看向量.以二维平面直角坐标系为例,i, j 分别是沿 2 个坐标轴方向的单位向量.那么坐标平面上的其他向量,例如 [ 3  -2 ] [3−与 i, j 是什么 ...

  10. 二本毕业,我是如何逆袭成为BAT年薪40W的Java工程师的?

    身边的师弟师妹经常问到:非计算机专业出身,你是在2年内如何逆袭成BAT年薪40W的资深开发工程师的.其实很简单——努力! 我16年毕业于普通的二本学校,非计算机专业出身,只因为对软件开发感兴趣,所以找 ...