PAT 1096 Consecutive Factors[难]
1096 Consecutive Factors (20 分)
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<231).
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
题目大意:给出数N,找出其最长连续因子,因子要从小选起。
//哇好难,越做越难,,,
#include <iostream>
#include <vector>
#include<math.h>
using namespace std; int main()
{
int n;
cin>>n;
int m=sqrt(n);
int maxl=,tp=,bg=;
vector<int> vt;
for(int i=;i<=m;i++){
int t=n;//这个i表示从哪个地方开始。
if(n%i==){
tp++;
t/=i;
if(tp>maxl){
maxl=tp;
bg=i;//就是这个开始的时候。但是你得能整除才可以。哇这个好难。
}
}else{
tp=;
}
}
cout<<maxl<<'\n';
for(int i=bg;i<maxl+tp;i++){
cout<<i;
if(i!=maxl+tp-)
cout<<"*";
}
return ;
}
//写不下去了,要考虑好多问题啊。
PAT 1096 Consecutive Factors[难]的更多相关文章
- PAT 1096. Consecutive Factors
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- 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
https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...
- PAT Advanced 1096 Consecutive Factors (20) [数学问题-因子分解 逻辑题]
题目 Among all the factors of a positive integer N, there may exist several consecutive numbers. For e ...
- 1096. Consecutive Factors (20)
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- PAT A1096 Consecutive Factors (20 分)——数字遍历
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- PAT (Advanced Level) 1096. Consecutive Factors (20)
如果是素数直接输出1与素数,否则枚举长度和起始数即可. #include<cstdio> #include<cstring> #include<cmath> #in ...
- PAT甲题题解-1096. Consecutive Factors(20)-(枚举)
题意:一个正整数n可以分解成一系列因子的乘积,其中会存在连续的因子相乘,如630=3*5*6*7,5*6*7即为连续的因子.给定n,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...
随机推荐
- JavaScript语言精粹读书笔记- JavaScript对象
JavaScript 对象 除了数字.字符串.布尔值.null.undefined(都不可变)这5种简单类型,其他都是对象. JavaScript中的对象是可变的键控集合(keyed collecti ...
- GitHub Permission to <<repository>> denied to <<username>>
I kept receiving a 403 error saying my usual username couldn’t access the repository with my usual a ...
- 小谈js原型链和继承
原型(prototype)在js中可是担当着举足轻重的作用,原型的实现则是在原型链的基础上,理解原型链的原理后,对原型的使用会更加自如,也能体会到js语言的魅力. 本文章会涉及的内容 原型及原型对象 ...
- Socket 进行发送
最灵活的通信方式还是Socket ,TcpClient和Tcplistener只是对Socket进行了一些包装,从而使他们使用起来更简单一些 给出同步的服务器端 static void Main(st ...
- iOS开发之--使用storyboard下,tabbar小图标和文字颜色的设置
在开发项目的时候,如果是使用故事版设计的架构,那么在设置tabbar小图标的时候,可能会出现一点小问题, 成功的设置方法如下: 1.设置seleectedImage和image,其实就是非选中状态的图 ...
- 获取 js DOM元素中绑定的所有事件,模仿 chrome getEventListeners
偶尔看到了这个问题,如何用JS获取元素某一事件上绑定的所有Listener? 突然觉得好像是有解决办法的,查了下,在 chrome 下,支持 window.getEventListeners(obj) ...
- JS:ES5数组基本操作
一.添加删除 push(): 尾部添加,返回数组 pop(): 尾部删除,返回删除项 unshift() : 头部添加,返回数组 shift() : 头部删除,返回删除项 二.插入.替换 万能spli ...
- SharePoint Managed Metadata 使用总结
前言 本文完全原创,转载请说明出处,希望对大家有用. 在SharePoint开发中,通常我们会将数据存储在列表,文档库或者直接存到数据库.但涉及到数据的层级结构时,用列表等存储实现并不是一件简单的事情 ...
- Ubuntu 16.04修改配置静态IP和DNS
Ubuntu 16.04修改配置静态IP和DNS 1.修改interfaces 文件 sudo gedit /etc/network/interfaces 2.添加 例如: auto enp0s25 ...
- windows下安装google protocbuf
首先安装setuptools: windows:======== 1.下载 ez_setup.py,安装setuptoolshttps://bitbucket.org/pypa/setuptools/ ...