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,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...
随机推荐
- java为安全起见对Applet有所限制
Applet消亡的原因: ①java为安全起见对Applet有所限制:Applet不允许访问本地文件信息.敏感信息,不能执行本地指令(比如FORMAT),不能访问初原服务器之外的其他服务器. ① IE ...
- 使用HashMap,put()表示放置元素,get()表示取元素
SortedSet可自动为元素排序. SortedSet的实现类是TreeSet:它的作用是字为添加到TreeSet中的元素排序. 与HashSet不同,TreeSet并不需要实现HashCode() ...
- java---同步与并发概念
Java中并发的形式无非是多线程和多进程两种形式.这两种形式都是可以利用多核来发挥计算能力的. 先说并发: 多进程意味着同时运行多个JVM,这个代价通常比多线程高,每个JVM都有自己的堆栈.都要分别加 ...
- "reason":"No handler for type [attachment] declared on field [file]" 最完全解决方案
0.elasticsearch-mapper-attachments 2.3.4安装 mapper-attachments安装方法分两类,在线和离线: 在线安装 bin/elasticsearch-p ...
- 《Programming with Objective-C》第七章 Values and Collections
1.平台相关的数据类型 These types, like NSInteger and NSUInteger, are defined differently depending on the tar ...
- superresolution_v_2.0 Application超分辨率程序文档
SUPERRESOLUTION GRAPHICAL USER INTERFACE DOCUMENTATION Contents 1.- How to use this application. 2.- ...
- javascript new Date()函数在不同浏览器上返回不同的值
今天是2015年3月16日,在IE 6 上new Date()返回给后台server的字符串格式为 "Mon Mar 16 00:00:00 UTC 0800 2015",而在f ...
- poj_3415 后缀数组+单调栈
题目大意 定义字符串T的子串T(i, k)=TiTi+1...Ti+k-1, 1≤i≤i+k-1≤|T|. 给定两个字符串A和B,定义集合S为S = {(i, j, k) | k≥K, A(i, k) ...
- 重启svn
重启svn svnserve -d -r /svn -d表示后台运行 -r 指定根目录是 /u02/svn
- AI画圆角矩形
如何画圆角矩形:设置矩形圆角大小 第一种方法:点击圆角矩形在画布上点一下; [caption id="attachment_878" align="alignnone&q ...