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,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...
随机推荐
- springboot中参数校验
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...
- ES6 学习 -- 解构赋值
一.数组解构 **数组解构,解构出来的值跟数组下标是一一对应的,如果左边变量多于右边数组,则左边后面部分变量值为undefined,如果右边数组元素个数多于左边解构变量个数,则左边变量全都有值,且一一 ...
- Docker学习のDocker的简单应用
一.常见基本docker命令 docker是在一个linux虚拟机上运行的(对于windows来说),打开Docker quickStart terminal,就连街上了docker的 daemon ...
- 从Hadoop+Storm架构转向Spark架构
- The linux command之高级键盘技巧
一.光标移动 二.修改文本 三.剪切和粘贴文本 四.使用历史命令
- Android开发 QRCode二维码开发第三方框架
前言 Android开发里二维码开发经常用到,这里简单的介绍下Android开发里的二维码. 最广泛使用的二维码库zxing zxing是最广泛的二维码库各个平台都可以适用它,但是Android平台使 ...
- code+第四次网络赛div2
T1 组合数问题: 用k个不完全相同的组合数表示一个数n. 用k-1个1和一个n-k+1表示即可. #include<cstdio> using namespace std; int x, ...
- python中的 += 语法的使用
python中有个缩略的写法,如下 a = a +1 等同于 a +=1 发现了一个有趣之处,+=的写法中间不能有空格,否则报错,测试如下 Python 3.7.1 (v3.7.1:260ec2c36 ...
- 廖雪峰Java16函数式编程-1Lambda表达式-1Lambda基础
1. 函数式编程 Java有2类方法: 实例方法:通过实例调用 静态方法:通过类名调用 Java的方法相当于过程式语言的函数 函数式编程(Functional Programing): 把函数作为基本 ...
- kaptcha 实现验证码
依赖 <dependency> <groupId>com.github.penggle</groupId> <artifactId>kaptcha< ...