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,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...
随机推荐
- Spring Cloud高级视频
Spring Cloud高级视频 第一章 微服务架构概述 第二章 开始使用Spring Cloud实战微服务 第三章 服务提供者与服务消费者 第四章 服务发现与服务注册 第五章 使用Hystrix保护 ...
- 如何使用Spring管理Filter和Servlet
在使用spring容器的web应用中,业务对象间的依赖关系都可以用context.xml文件来配置,并且由spring容器来负责依赖对象 的创建.如果要在filter或者servlet中使用sprin ...
- gmock 简单笔记
std::shared_ptr<MockThreadRCInvester> spMockaAcc; HelperThreadRCInvester helperAcc; // spMockA ...
- mysql 存储过程学习 汇总
存储过程框架 DEMILITER $$ -- 重定义符 DROP PROCEDURE IF EXISTS store_procedure$$ -- 如果存在此名的存储过程,先删除 CREATE PRO ...
- Java 多线程 - 锁的类型
https://zhuanlan.zhihu.com/p/37287566 https://www.cnblogs.com/qifengshi/p/6831055.html
- JPA 基本使用
ORM简介 对象关系映射(Object Relational Mapping,简称ORM),是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换. 实现ORM思想的框架:Mybati ...
- thinkphp 闭包支持
闭包定义 我们可以使用闭包的方式定义一些特殊需求的路由,而不需要执行控制器的操作方法了,例如: 'URL_ROUTE_RULES'=>array( 'test' => function() ...
- BCB编写DLL终极手册
一. 编写 DLL File/New/Dll 生成 Dll 的向导,然后能够添加导出函数和导出类 导出函数:extern "C" __declspec(dllexport) Exp ...
- CygWin、MinGw和Msys的区别
做了6年的Windows C++,觉得已经没什么挑战力:而且Windows C++已经没落,不得不转Linux C++: 习惯了Windows的界面,习惯了傻瓜式的VS IDE,现在遇到Linux命令 ...
- Activity详解三 启动activity并返回结果 转载 https://www.cnblogs.com/androidWuYou/p/5886991.html
首先看演示: 1 简介 .如果想在Activity中得到新打开Activity 关闭后返回的数据,需要使用系统提供的startActivityForResult(Intent intent, int ...