PAT甲级——A1096 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<).
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 <iostream>
#include <vector>
#include <cmath>
using namespace std;
int N, num = , first = -;
int main()
{
cin >> N;
for (int i = ; i <= (int)sqrt(N*1.0); ++i)//2~根号N
{
if (N%i == )
{
int nn = ;
for (int j = i; N%j == ; j*=i+nn)//从i开始的连续数字,确保能连续除下去,而不是除以一个数字
++nn;
if (nn > num)//更新最长数字串
{
first = i;
num = nn;
}
}
}
if (num == )//N就是质数
cout << << endl << N << endl;
else
{
cout << num << endl;
for (int i = ; i < num; ++i)
cout << first + i << (i == num - ? "" : "*");
}
return ;
}
PAT甲级——A1096 Consecutive Factors【20】的更多相关文章
- PAT甲级——1096 Consecutive Factors (数学题)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors ...
- 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 ...
- 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) 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 ...
- A1096. Consecutive Factors
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- 【PAT甲级】1096 Consecutive Factors (20 分)
题意: 输入一个int范围内的正整数,输出它最多可以被分解为多少个连续的因子并输出这些因子以*连接. trick: 测试点5包含N本身是一个素数的数据,此时应当输出1并把N输出. 测试点5包含一个2e ...
- PAT甲题题解-1096. Consecutive Factors(20)-(枚举)
题意:一个正整数n可以分解成一系列因子的乘积,其中会存在连续的因子相乘,如630=3*5*6*7,5*6*7即为连续的因子.给定n,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...
随机推荐
- SonarQube代码质量扫描持续集成
1.安装JDK和配置JAVA_HOME和CLASSPATH 2.安装mysql数据库 3.创建数据库和用户 mysql -u root -p mysql> CREATE DATABASE son ...
- ASP.NET MVC easyUI-datagrid 的当前页合计and总合计
一.HTML代码 <table id="dg" class="easyui-datagrid" style="width: 100%; heig ...
- RabbitMQ学习第一记:用java连接RabbitMQ
1.什么是RabbitMQ MQ(Message Queue):消息队列,是服务端设计的一个可以存储大量消息的队列,并提供客户端操作队列的方法:生产队列(向队列中添加数据).消费队列(从队列中取数据) ...
- Python学习笔记(三)——文件系统中的常用方法
OS模块中关于文件/目录常用的函数使用方法 函数名 使用方法 getcwd() 返回当前工作目录 chdir() 改变工作目录 listdir(path='.') 列举指定目录中的文件名('.'表示当 ...
- Erlang学习记录:运算符
数学运算符 说明 详细 符号 加减乘 +-* 浮点数除 结果为浮点数 / 整数除 除数和被除数都必须是整数,结果为整数 div 整数取余 rem 逻辑运算符 说明 符号 详细 and 前后两个值都为真 ...
- 0704 Process继承实现多进程、Pool进程池,进程间通过队列通信,Pool实现多进程实现复制文件
通过继承的方式,实现Process多进程 from multiprocessing import Process import time class MyNewProcess(Process): de ...
- Maven远程仓库地址修改(精)
国内最快的maven镜像 阿里云maven镜像 <repositories> <repository> <id>spring-snapshots</id&g ...
- exit与return的区别
===========================PHP的解释=========================================================== return ...
- 海量数据解决思路之Hash算法
海量数据解决思路之Hash算法 一.概述 本文将粗略讲述一下Hash算法的概念特性,里边会结合 分布式系统负载均衡 实例对Hash的一致性做深入探讨.另外,探讨一下Hash算法在海量数据处理方案中 ...
- 3列滚动抽奖 jquery.slotmachine
效果图: 需引入js文件: <script src="js/jquery-3.2.0.js"></script> <script src=" ...