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<).

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 <stdio.h>
#include <algorithm>
#include <set>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = ;
ll n; int main(){
scanf("%lld",&n);
ll res=,res_j=,res_i=; for(ll i=;i*i<=n;i++){
ll sum=,j=i;
while(){
sum*=j;
if(n%sum!=)break;
j++;
}
j--;
if(j-i+>res){
res=j-i+;
res_j=j;
res_i=i;
}
}
if(res==) {
printf("1\n%lld",n);
return ;}
printf("%lld\n",res);
for(int i=res_i;i<res_j;i++){
printf("%lld*",i);
}
printf("%lld",res_j);
}

注意点:一开始找成了所有因子都连续,结果一直是0,后来发现只要能整除就好了。其实和找质数也差不多

第二点是要用long long 不能用int,虽然题目输入是int范围,但是你的乘积结果会超int,导致死循环。

第三点是遍历上限到sqrt(n)就好了,否则会超时,因为sqrt(n) * (sqrt(n)+1) 肯定大于n了。

第四点是遇到质数要输出自己,不是只判断2和3就好了,只要看res是不是还是0。

PAT A1096 Consecutive Factors (20 分)——数字遍历的更多相关文章

  1. 【PAT甲级】1096 Consecutive Factors (20 分)

    题意: 输入一个int范围内的正整数,输出它最多可以被分解为多少个连续的因子并输出这些因子以*连接. trick: 测试点5包含N本身是一个素数的数据,此时应当输出1并把N输出. 测试点5包含一个2e ...

  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 (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 ...

  4. PAT Advanced 1096 Consecutive Factors (20) [数学问题-因子分解 逻辑题]

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

  5. PAT 1096 Consecutive Factors[难]

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

  6. PAT 1088 三人行(20 分)(暴力破解+流程分析)

    1088 三人行(20 分) 子曰:"三人行,必有我师焉.择其善者而从之,其不善者而改之." 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整数:把甲的能力值的 ...

  7. PAT 1096. Consecutive Factors

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

  8. pat 1035 Password(20 分)

    1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...

  9. PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)

    1061 Dating (20 分)   Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...

随机推荐

  1. Vsftpd+Tengine+SpringMVC实现上传图片

    第三部分:SpringMVC实现上传 1.1 思路 (1)使用SpringMVC上传组件,从页面表单接收图片 (2)使用vsftpd组件,将图片上传到Linux服务器 a.服务端:在Linux上安装f ...

  2. ViewModel处理View相关事件的多种方式(非技术贴,仅学习总结)

    众所周知,在UWP中,微软为我们提供了一种新的绑定方式:x:bind,它是基于编译时的绑定.在性能方面,运行时绑定Binding与它相比还是有些逊色的.因此针对一些确定的.不需要变更的数据,我们完全有 ...

  3. Python 练习: 简单角色游戏程序

    要求: 1.创建三个游戏人物,分别是: 苍井井,女,18,初始战斗力1000 东尼木木,男,20,初始战斗力1800 波多多,女,19,初始战斗力2500 2.游戏场景,分别: 草丛战斗,消耗200战 ...

  4. SuperMap iObject .NET开发完成后私有部署,打包安装

    转载自:http://blog.csdn.net/supermapsupport/article/details/53319800 作者:皇皇 SuperMap iObjict .NET组件开发结束后 ...

  5. Centos 6.8 系统升级默认的Python版本

    1.编译安装python2.7 # wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz # Python-2.7.12.tg ...

  6. loadrunner 运行脚本-Run-time Settings之Pacing设置

    运行脚本-Run-time Settings之Pacing设置 by:授客 QQ:1033553122   As soon as the previous iteration ends 前一个迭代一结 ...

  7. loadrunner 脚本优化-关联设置

    脚本优化-关联设置 by:授客 QQ:1033553122 关联的原理 关联也属于一钟特殊的参数化.一般参数化的参数来源于一个文件.一个定义的table.通过sql写的一个结果集等,但关联所获得的参数 ...

  8. 安卓开发_深入理解Handler消息传递机制

    一.概述 因为子线程的run()方法无法修改UI线程(主线程)的UI界面,所以Android引入了Handler消息传递机制,实现在新创建的线程中操作UI界面 二.消息类(Message) 消息类是存 ...

  9. 心迹 使用说明&功能展示

    下载地址 心迹.apk 更新于2018.8.9 11:47 测试账号:用户名testing,密码testing 项目地址 GitHub 注册&登录 第一次使用心迹app时,必须进行注册,以便区 ...

  10. 【第三篇】SAP ABAP7.5x新语法之程序结构&SubScreen

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文地址:SAP ABAP7.5x系列之程序结构& ...