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 ...
随机推荐
- Linux基础-命令概述
概述 很多人可能在电视或电影中看到过类似的场景,黑客面对一个黑色的屏幕,上面飘着密密麻麻的字符,梆梆一顿敲,就完成了窃取资料的任务,是不是很帅!我们作为一个开发者, 即使不为了成为上述的人, 也需要会 ...
- ztree 数组和树结构互转算法
//树转化为数组transformToArrayFormat: function (setting, nodes) { if (!nodes) return []; var childKey = se ...
- sql合并字段
<!-- 对发送方式合并查询 --> <!--查询所有满足条件的营销活动 --> <select id="CRM-MK-ACT-DEFINE-SELECT&qu ...
- java中传参的要点
传参的是分为:值传递和引用传递,值传递不会改变值,传递的是这个值的副本(就是把这个值拿出来拷贝一份用拷贝的值):引用传递会改变值,传递的是这个值的“地址”: String是特殊的引用类型,用Strin ...
- 将arcEngine9.3和dev9.2.4开发的项目升级成arcObject10.2和dev15.1.3过程中遇到的问题和解决
好久没碰.net了,arcgis更是感觉都忘干净了,今天将arcEngine9.3和dev9.2.4开发的一个项目升级成arcObject10.2和dev15.1.3过程中遇到了一系问题,留个笔记,留 ...
- MATLAB中图像处理的函数
表1 图像显示 函数名 功能说明 函数名 功能说明 colorbar 颜色条显示 montage 按矩形剪辑方式显示多帧图像 getimage 从坐标系中获取图像数据 immovie 从多帧索引图像中 ...
- Codeforces 1175E 倍增
题意:给你n个区间和m次询问,每次询问一个区间[l, r]至少需要几个区间覆盖? 思路:如果只有一个区间,并且区间是整个取值范围的话,这是一个经典的区间覆盖问题,我们都知道贪心可以解决.现在我们需要快 ...
- ida x32 dbg 动态调试
http://www.xrwcn.com/html/8.html 0x20019u 注册表 RegOpenKeyEx函数 LONG RegOpenKeyEx( HKEY hKey, // handle ...
- 【JS学习】慕课网2-7 练习题:制作新按钮,“新窗口打开网站” ,点击打开新窗口。
要求: 1.新窗口打开时弹出确认框,是否打开 提示: 使用 if 判断确认框是否点击了确定,如点击弹出输入对话框,否则没有任何操作. 2.通过输入对话框,确定打开的网址,默认为 http://www. ...
- 【读书笔记】剑指offer
导语 所有的编程练习都在牛客网OJ提交,链接: https://www.nowcoder.com/ta/coding-interviews 九章算法的 lintcode 也有这本书的题目.https: ...