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. js 前端有消息了 声音提示给用户

    前言:工作中有需求,在数据变更有变更时采用声音提示给用户,这里记录一下.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9936180.html 网站地址:我的个 ...

  2. js之返回网页顶部

    目标效果:浏览网页过程中,滑动滚轮,显示返回顶部按钮,点击返回顶部后,返回网页顶端. 代码如下: <!DOCTYPE html> <html lang="en"& ...

  3. 从零开始学习html(七)CSS样式基本知识

    一.内联式css样式,直接写在现有的HTML标签中 <!DOCTYPE HTML> <html> <head> <meta http-equiv=" ...

  4. 纯小白入手 vue3.0 CLI - 2.7 - 组件之间的数据流

    vue3.0 CLI 真小白一步一步入手全教程系列:https://www.cnblogs.com/ndos/category/1295752.html 尽量把纷繁的知识,肢解重组成为可以堆砌的知识. ...

  5. Fragment 中 ListView绑定ContextMenu

    package com.example.administrator.imbobo.controller.fragment; import android.content.BroadcastReceiv ...

  6. [20170628]11g修改用户名.txt

    [20170628]11g修改用户名.txt --//昨天看了链接,提到修改用户名:http://www.oratea.com/2017/06/26/oracle-11g%e4%bf%ae%e6%94 ...

  7. python第七十七天---HTML

    HTML5 :规则, 浏览器的通用规则 1.规则, 浏览器的通用规则 2.开发者: 学习html 规则 开发后台程序 - 写html文件 (当作模板) - 数据库获取数据,替换到指定的HTML文件中的 ...

  8. C++中cin.clear()的用法

    我们谈谈cin.clear的作用,第一次看到这东西,很多人以为就是清空cin里面的数据流,而实际上却与此相差很远,首先我们看看以下代码: #include <iostream>  usin ...

  9. C#语言————第一章 第一个C#程序

    第一章    第一个C#程序 ******************C#程序***************     ①:建立项目:文件-->新建-->项目-->c#-->控制台程 ...

  10. 07LaTeX学习系列之---Latex源文件的结构

    目录 目录: (一)Latex源文件的结构: (二)基础语法: 2.空行: 3.document: 4.数学公式: 5.latex的文件格式分类: 目录: 本系列是有关LaTeX的学习系列,共计19篇 ...