PAT Advanced 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
567
题目分析
已知一个整数N,求所有N的连续因子因式分解中,最长连续因子个数和最小连续因子序列
注:最小连续因子序列的长度其实就是最长连续因子个数(因为连续因子序列的第一个数越大,连续因子序列越短)
解题思路
- 连续因子数
1.1 若为0,表示N是质数,因子只有1和N本身
1.2 若大于0
1.2.1 若等于1,表示N因子分解后,一个因子<=sqr(n),一个因子>=(sqr(n))
1.2.2 若大于1,表示N因子分解后,可以找到连续因子 
易错点
- 注意连续因子数为0和连续因子树为1的不同情况区分
 - 最小连续因子序列的长度其实就是最长连续因子个数(因为连续因子序列的第一个数越大,连续因子序列越短)
 
Code
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc,char * argv[]) {
	int n;
	scanf("%d",&n);
	int sqr=(int)sqrt(1.0*n);
	int len = 0,first=0;
	for(int i=2; i<=sqr; i++) {
		int temp =1;
		int j;
		for(j=i; j<=sqr; j++) {
			temp*=j;
			if(n%temp!=0)break;
		}
		if(j-i>len) {
			len=j-i;
			first = i;
		}
	}
	if(len==0) printf("1\n%d", n);
	else {
		printf("%d\n",len);
		for(int i=first; i<first+len; i++) {
			if(i!=first)printf("*");
			printf("%d", i);
		}
	}
	return 0;
}
												
											PAT Advanced 1096 Consecutive Factors (20) [数学问题-因子分解 逻辑题]的更多相关文章
- 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 ...
 - 1096. Consecutive Factors (20)
		
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 (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,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...
 - 【PAT甲级】1096 Consecutive Factors (20 分)
		
题意: 输入一个int范围内的正整数,输出它最多可以被分解为多少个连续的因子并输出这些因子以*连接. trick: 测试点5包含N本身是一个素数的数据,此时应当输出1并把N输出. 测试点5包含一个2e ...
 - PAT Advanced 1132 Cut Integer (20) [数学问题-简单数学]
		
题目 Cutting an integer means to cut a K digits long integer Z into two integers of (K/2) digits long ...
 - PAT Advanced 1088 Rational Arithmetic (20) [数学问题-分数的四则运算]
		
题目 For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate ...
 
随机推荐
- 2. FTP 服务器安装
			
vsftp 安装(linux) Linux : 安装,创建虚拟用户,配置,防火墙设置 1. 安装 执行yum -y install vsftpd 注意: (1) 是否使用sudo权限执行请根据您具体环 ...
 - 新手学Java,有哪些入门知识点?
			
很多小伙伴们在刚接触Java的时候,会有些迷茫,不知道该从哪里入手,不管是做前端还是后端,程序员都会用到JAVA,那该掌握哪些必要的基础知识呢.今天就跟大家分享新手学Java,有哪些入门知识点? 下面 ...
 - Django 初体验
			
Django 依赖的python 基础环境安装: https://www.runoob.com/django/django-install.html Django安装参考官网文档: https://d ...
 - centos7-虚拟机 主机 互通 静态ip网络设置
			
由于目前互联网发展的速度之快.用户量之多,很多时候作为服务端单台服务器的硬件配置已经不足以支撑业务.集群.分布式等技术架构变得越来越普及,作为开发人员也有必要掌握相关技能.笔者打算选用virtual ...
 - Linux学习《第二章命令》本章小结
			
经过这一章的学习,了解了常用的命令.这是学习Linux系统最最基础的工作,必须努力掌握,个人觉得,并不是这个章节学习结束之后,命令的学习就结束了,而是刚刚开始,今后在每个知识点学习过程中,都会 学习到 ...
 - oracle 的存储过程
			
-----推荐视频 https://ke.qq.com/webcourse/index.html#course_id=292495&term_id=100346599&taid= ...
 - 四、CI框架之通过URL路径访问C中的函数
			
一.在C中写一个test001函数 二.在路径http://127.0.0.1/CodeIgniter-3.1.10/index.php/welcome/test001中访问 不忘初心,如果您认为这篇 ...
 - OC项目加入swift第三方库遇到的坑
			
https://www.jianshu.com/p/96d868dcd69c 2017.07.07 16:23* 字数 295 阅读 5218评论 2喜欢 4 首先,在OC项目的Podfile文件中添 ...
 - 干货|微软远程桌面服务蠕虫漏洞(CVE-2019-1182)分析
			
2019年8月,微软发布了一套针对远程桌面服务的修复程序,其中包括两个关键的远程执行代码(RCE)漏洞,CVE-2019-1181和CVE-2019-1182.与之前修复的"BlueKeep ...
 - POJ1200  A - Crazy Search(哈希)
			
A - Crazy Search Many people like to solve hard puzzles some of which may lead them to madness. One ...