PAT_A1096#Consecutive Factors
Source:
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的更多相关文章
- 1096. Consecutive Factors (20)
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- PAT1096:Consecutive Factors
1096. Consecutive Factors (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...
- PAT A1096 Consecutive Factors (20 分)——数字遍历
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- A1096. Consecutive Factors
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- PAT 甲级 1096 Consecutive Factors
https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...
- PAT 1096 Consecutive Factors[难]
1096 Consecutive Factors (20 分) Among all the factors of a positive integer N, there may exist sever ...
- PAT甲级——1096 Consecutive Factors (数学题)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors ...
- 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 ...
- PAT 1096. Consecutive Factors
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
随机推荐
- java线程池监控
原因 最近在完善公司的基础发布平台的时候,使用到了一线程去做一些异步的事情,在开发环境和测试环境验证没有任何问题,但是在程序在生产运行一段时间后,发现没有得到自己想要的结果,为此开始了漫长的排查bug ...
- Tomcat 配置安装
1 下载和安装Tomcat服务器 Tomcat官方站点:http://jakarta.apache.org 下载Tomcat安装程序包:http://tomcat.apache.org/ 启动和测试T ...
- 7.使用mysql_export监控mysql
ok,docker监控,宿主机CPU.磁盘.网络.内存监控我们都已讲过,是时候讲一波mysql监控了.本次mysql部署在客户端. 架构 客户端 MySql安装 ##下载mysql的repo源: [r ...
- winserver 2008 找不到回收站的解决办法
桌面新建文件夹,命名为 “回收站.{645ff040-5081-101b-9f08-00aa002f954e}”,就可以了.
- python-前端JS
JavaScript JS(JavaScript)和 JAVA是没有任何关系的,使前端语言动作的基础 特点:现在对前端所有的动作操作都是基于JS操作的.是一门逻辑语言 简单易用:可以使用任何文本编辑工 ...
- 通用唯一标识码UUID的介绍及使用。
什么是UUID? UUID全称:Universally Unique Identifier,即通用唯一识别码. UUID是由一组32位数的16进制数字所构成,是故UUID理论上的总数为16^32 = ...
- android中的原始资源的使用
原始资源可以放在两个地方: 1.位于/res/raw目录下,android SDK会处理该目录下的原始资源,android SDK会在R清单类中为该目录下的资源生成一个索引项. 2.位于/assets ...
- linux常用命令-1系统相关命令
hostname #计算机名 passwd #修改密码 reboot #重启 shutdown –r now #立刻重启(root用户使用) shutdown –r 10 #过10分钟自动重启(roo ...
- KiCAD原理图导出PDF方法
KiCAD原理图导出为PDF 1.文件->绘制 2.按照下图选择保存目录和输出格式后,选择绘制当前页或者所有页
- linux下nano命令大全
nano是一个字符终端的文本编辑器,有点像DOS下的editor程序.它比vi/vim要简单得多,比较适合Linux初学者使用.某些Linux发行版的默认编辑器就是nano. nano命令可以打开指定 ...