Source:

PAT A1096 Consecutive Factors (20 分)

Description:

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

Keys:

Attention:

  • 注意质数的情况
  • 若n存在因子factor0,使得factor0*factor0>n,则factor0唯一;即其余factor,全部有factor*factor<=n

Code:

 /*
Data: 2019-07-08 19:35:10
Problem: PAT_A1096#Consecutive Factors
AC: 31:02 题目大意:
正整数N可以分解为多组因数乘积的形式,选择含有最长连续因数的一组,打印该连续因数
因数中不含1,打印序列递增且较小的
*/
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL; int main()
{
LL n;
scanf("%lld", &n);
vector<LL> ans,temp;
for(LL i=; i<=(LL)sqrt(1.0*n); i++)
{
LL sum=;
temp.clear();
for(LL j=i; j<=n; j++)
{
sum *= j;
if(n%sum != )
break;
temp.push_back(j);
}
if(temp.size() > ans.size())
ans = temp;
}
if(ans.size()==)
printf("1\n%lld", n);
else
printf("%d\n", ans.size());
for(int i=; i<ans.size(); i++)
printf("%d%c", ans[i], i==ans.size()-?'\n':'*'); return ;
}

PAT_A1096#Consecutive Factors的更多相关文章

  1. 1096. Consecutive Factors (20)

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

  2. PAT1096:Consecutive Factors

    1096. Consecutive Factors (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  3. PAT A1096 Consecutive Factors (20 分)——数字遍历

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

  4. A1096. Consecutive Factors

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

  5. PAT 甲级 1096 Consecutive Factors

    https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...

  6. PAT 1096 Consecutive Factors[难]

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

  7. PAT甲级——1096 Consecutive Factors (数学题)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors  ...

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

  9. PAT 1096. Consecutive Factors

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

随机推荐

  1. linux 日志文件查看

    记录下日志中常用的日志查看命令. 1.  tail -n 10 -f  **.log 显示日志文件尾部10行日志,当有新日志产生,会追加显示. 2. tail 命令 现ff.sh中有如下信息: [ro ...

  2. activiti7完成当前任务

    package com.zcc.acvitivi; import org.activiti.engine.ProcessEngine;import org.activiti.engine.Proces ...

  3. Windows XP 下如何使用Qt Creator中的Git版本控制功能

     原文地址:http://www.qtcn.org/bbs/simple/?t16960.html Qt Creator是针对Qt应用开发平台专门设计的IDE开发工具,集成了很多功能,分别有win ...

  4. awk 按小时 统计接口调用次数

    #统计所有接口总量awk -F ' ' '{a[$7]++} END{for(i in a){print i,a[i] | "sort -r -k 7"}}' accesslog/ ...

  5. 将xml文件转为txt文件

    import os import re import sys import glob import xml.etree.ElementTree as ET def xml_to_txt(indir,o ...

  6. Python中过滤HTML标签的函数

    #用正则简单过滤html的<>标签 import re str = "<img /><a>srcd</a>hello</br>&l ...

  7. imagepicker插件的使用方法和选择按钮汉化

    1,使用cordova-plugin-image-picker插件. cordova plugin add https://github.com/wymsee/cordova-imagePicker. ...

  8. maven spring-mvc mybatis整合

    一 首先在myeclipse中安装好maven插件. 1.下载地址:http://mirror.bit.edu.cn/apache/maven/maven-3/3.0.5/binaries/apach ...

  9. 2018-8-10-win10-UWP-圆形等待

    title author date CreateTime categories win10 UWP 圆形等待 lindexi 2018-08-10 19:16:50 +0800 2018-2-13 1 ...

  10. JNI Hello World

    1.什么是JNI:               JNI(Java Native Interface):java本地开发接口               JNI是一个协议,这个协议用来沟通java代码和 ...