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. [UWP 自定义控件]了解模板化控件(8):ItemsControl

    1. 模仿ItemsControl 顾名思义,ItemsControl是展示一组数据的控件,它是UWP UI系统中最重要的控件之一,和展示单一数据的ContentControl构成了UWP UI的绝大 ...

  2. [T-ARA N4/二段横踢][Can We Love]

    歌词来源:http://music.163.com/#/song?id=26310867 Can We Love Can We Love [Can We Love Can We Love] Can W ...

  3. Net-SNMP V3协议 安装配置笔记(CentOS 6.3/5.6)

    注意:snmp V3,需要需要关闭selinux和防火墙: 关闭selinux方法: #vi /etc/selinux/config 将文件中的SELINUX="" 为 disab ...

  4. 素数问题练习_HDOJ1262

    HDOJ1262_寻找素数对 和上一篇博客一样的解法,将10000以内的所有素数求出即可解题. #include<stdio.h> #include<stdlib.h> #in ...

  5. Spring整合SpringMVC

    整合:把在springMVC配置文件中的spring提取出来整合为另一份配置文件 希望: 1).Spring的配置文件只是用来配置和业务逻辑有关的功能(数据源.事务控制.切面....) 2).Spri ...

  6. 传输层中的协议 TCP & UDP

    面向连接的TCP协议 “面向连接”就是在正式通信前必须要与对方建立起连接.比如你给别人打电话,必须等线路接通了.对方拿起话筒才能相互通话.TCP(Transmission Control Protoc ...

  7. linux bin & sbin different

    linux bin & sbin different flutter & $PATH http://blog.taylormcgann.com/2014/04/11/differenc ...

  8. jmeter 创建web测试计划

    测试用例: 1 创建5个用户发送请求到2个web页面: 2 发送3次请求 总请求=5*2*3=30 创建这个测试计划需要用到以下元素:thread groups / http request / ht ...

  9. 激活win10专业版

    每180天激活一次

  10. 配合es5.8的使用,升级sb版本到2.X,遇到一个问题

    问题:Failed to bind properties under 'spring.redis.jedis.pool.max-wait' to java.time.Duration: Propert ...