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. Android 发布自动版本号方案

    以前看到一些自动化版本号打包的文章.如果您的项目是用 Git 管理的,并且恰巧又是使用 Gradle 编译(应该绝大部分都是这样的了吧?),本文试图找到一种更加优雅的自动版本管理方法. 背景 我们都知 ...

  2. idea Maven 一键 mvn clean package

    文章目录 方法一 方法二 方法一 方法二

  3. VMware Workstation Pro 15.5.0 官方版本及激活密钥

    0x01:下载连接: https://download3.vmware.com/software/wkst/file/VMware-workstation-full-15.5.1-15018445.e ...

  4. Centos6下实现Nginx+Tomcat实现负载均衡及监控

    在性能测试过程中,我们可能会关注很多指标,比如CPU.IO.网络.磁盘等,通过这些指标大致可以判断哪个环节遇到了性能瓶颈,但是当这些指标无法判断出性能瓶颈时,我们可能就需要对一些中间件进行监控,比如N ...

  5. CFile CStdioFile CArchive 文件操作之异同(详细)

    两者的主要区别: 一. CFile类操作文件默认的是Binary模式,CStdioFile类操作文件默认的是Text模式.    在Binary模式下我们必须输入'\r\n',才能起到回车换行的效果, ...

  6. python获取港股通每日成交信息

    接口:ggt_daily 描述:获取港股通每日成交信息,数据从2014年开始 限量:单次最大1000,总量数据不限制 积分:用户积2000积分可调取,5000积分无限制,请自行提高积分,具体请参阅本文 ...

  7. window下Mysql 恢复Delete删除的数据

    转载:https://www.cnblogs.com/q149072205/p/11940591.html 本机用的Navicat连mysql测试DB又连了正式DB,因为本地与正式要频繁操作所以都打开 ...

  8. 【LeetCode】排序

    [349] Intersection of Two Arrays [Easy] 两个无序可重复数组找交集, 交集要求元素唯一. Given nums1 = [1, 2, 2, 1], nums2 =  ...

  9. java多线程并发面试题

    1.多线程有什么用? (1)发挥多核CPU的优势 随着工业的进步,现在的笔记本.台式机乃至商用的应用服务器至少也都是双核的,4核.8核甚至16核的也都不少见,如果是单线程的程序,那么在双核CPU上就浪 ...

  10. poj 3294 后缀数组+二分

    题目大意: 给定n个字符串,求出现在不小于k个字符串中的最长子串 基本思路: 二分长度,统计个数,一般套路,就是这个跟说好的不一样啊,我非得开2倍才不re,真他妈不爽,先二分找出长度,然后根据长度输出 ...