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
#include<stdio.h>
#include<math.h>
int main()
{
int MAX = ,n,index;
scanf("%d",&n);
int m = sqrt(double(n));
for(int i = ; i <= m ;++i)
{
int k = i;
int tmp = n;
while(tmp%k == )
{
tmp = tmp / k;
++k;
}
if(k - i > MAX)
{
MAX = k - i;
index = i;
}
}
if(MAX == )
{
printf("1\n");
printf("%d\n",n);
return ;
}
printf("%d\n",MAX);
for(int i = index ;i < index + MAX;++i)
{
if(i == index)
{
printf("%d",index);
}
else
{
printf("*%d",i);
}
}
printf("\n");
}
1096. Consecutive Factors (20)的更多相关文章
- 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 Advanced 1096  Consecutive Factors (20) [数学问题-因子分解 逻辑题]
		
题目 Among all the factors of a positive integer N, there may exist several consecutive numbers. For e ...
 - PAT甲题题解-1096. Consecutive Factors(20)-(枚举)
		
题意:一个正整数n可以分解成一系列因子的乘积,其中会存在连续的因子相乘,如630=3*5*6*7,5*6*7即为连续的因子.给定n,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...
 - PAT (Advanced Level) 1096. Consecutive Factors (20)
		
如果是素数直接输出1与素数,否则枚举长度和起始数即可. #include<cstdio> #include<cstring> #include<cmath> #in ...
 - 【PAT甲级】1096 Consecutive Factors (20 分)
		
题意: 输入一个int范围内的正整数,输出它最多可以被分解为多少个连续的因子并输出这些因子以*连接. trick: 测试点5包含N本身是一个素数的数据,此时应当输出1并把N输出. 测试点5包含一个2e ...
 - PAT甲级——1096 Consecutive Factors (数学题)
		
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive 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
		
https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...
 - PAT 1096. Consecutive Factors
		
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
 
随机推荐
- Android开发 SDK NDK下载
			
2014.7版本 ADT Bundle http://dl.google.com/android/adt/adt-bundle-windows-x86-20140702.ziphttp://dl.go ...
 - 《MFC游戏开发》笔记十 游戏中的碰撞检测进阶:地图类型&障碍物判定
			
本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9394465 作者:七十一雾央 新浪微博:http:// ...
 - 0. SQL Server监控清单
			
数据库服务器的监控可大致分为两类: (1) 状态监控:数据库服务器有没有在健康地运行? (2) 性能监控:健康运行的同时,有没有性能问题?可不可以更快些? 一. 服务器 1. 状态监控 (1) 服务器 ...
 - 【Amazon Linux】免费搭建subversion服务器
			
Amazon的EC2服务器可以免费试用一年.在这里申请: https://aws.amazon.com/cn/free/ 尝试把它弄成一个svn库来保存代码.按照 http://northwaygam ...
 - JavaScript 中的算术运算
			
JavaScript中算术运算在溢出(overflow).下溢(underflow)或被零整除时不会报错,当数字运算结果超过了JavaScript所能表示的数字上限(溢出),结果为一个特殊的无穷大(i ...
 - apache2.4的安装与卸载
			
安装sudo apt-get install apache2,这不是源码安装的方式,产生的apache地址在/etc/apache2,配置文件是apache2.conf如果浏览器输入127.0.0.1 ...
 - 剑指Offer33 第一个只出现一次的字符
			
/************************************************************************* > File Name: 33_FirstN ...
 - Javascript -- Math.round()、Math.ceil()、Math.floor()、parseInt去小数取整总结
			
一.Math.round() 作用:四舍五入返回整数.(返回参数+0.5后,向下取整) Math.round(5.57) //返回6 Math.round(2.4) //返回2 Math.round( ...
 - 跟我学习dubbo-Dubbo管理控制台的安装(3)
			
Dubbo管理控制台的安装 1.Dubbo管理控制台的主要作用:服务治理 2.管理控制台主要包含: 路由规则 动态配置 服务降级 访问控制 权重调整 负载均衡等管理功能 3.管理控制台版本: 当前稳定 ...
 - [转]oracle 实现插入自增列
			
本文转自:http://blog.csdn.net/love_zt_love/article/details/7911104 刚使用oracle,它和sql server 好多地方还是有所不同的,简单 ...