1096. Consecutive Factors (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 思路
因为12! < 2^31 < 13!。
所以,因子大小不会超过12!,连续因子的长度不会超过12。
从长度为12开始减小,令res为满足条件的最大因子,穷举所有可能直到满足N % res == 0就行。
注:穷举的过程中res会溢出,不过不影响结果。。
代码
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int N;
while(cin >> N)
{
int maxnum = sqrt(N);
for(int len = 12;len >= 1;len--)
{
for(int start = 2; start <= maxnum;start++)
{
int res = 1;
for(int i = start;i - start < len;i++)
{
res *= i;
}
if(N % res == 0)
{
cout << len << endl << start;
for(int j = start + 1;j - start < len;j++)
cout << "*" << j;
return 0;
}
}
}
cout << 1 << endl;
cout << N;
}
}

  

PAT1096:Consecutive Factors的更多相关文章

  1. 1096. Consecutive Factors (20)

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  2. PAT A1096 Consecutive Factors (20 分)——数字遍历

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  3. A1096. Consecutive Factors

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  4. PAT 甲级 1096 Consecutive Factors

    https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...

  5. PAT 1096 Consecutive Factors[难]

    1096 Consecutive Factors (20 分) Among all the factors of a positive integer N, there may exist sever ...

  6. PAT甲级——1096 Consecutive Factors (数学题)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors  ...

  7. 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 ...

  8. PAT 1096. Consecutive Factors

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  9. PAT_A1096#Consecutive Factors

    Source: PAT A1096 Consecutive Factors (20 分) Description: Among all the factors of a positive intege ...

随机推荐

  1. Linux常用命令(第二版) --权限管理命令

    权限管理命令 1.chmod[change the permissions mode of a file] : /bin/chmod 语法: chmod [{ugo}{+-=}{rwx}] [文件或目 ...

  2. 关于GPL329A中获取摄像头sensor id的问题

    首先我拿到了sensor_id应用程序的源码,我要在上面添加获取ov2685 的 sensor id的代码. 利用find . -name  get_sensor_id找到该代码编译之后生成的a.ou ...

  3. css选择器应用

    .mynav li:not(:last-child) { margin-right: 20px; }

  4. H5页面转成图片并下载到本地

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  5. django-debug-toolbar的配置以及使用

    django-debug-toolbar django,web开中,用django-debug-toolbar来调试请求的接口,无疑是完美至极.   可能本人,见识博浅,才说完美至极, 大神,表喷,抱 ...

  6. tomcat jvm优化

    tomcat优化(全) (2012-09-26 10:12:59) 转载▼ 标签: 杂谈 分类: java 1.内存设置(VM参数调优)(1). Windows环境下,是tomcat解压版(执行sta ...

  7. JVM笔记8-虚拟机性能监控与故障处理工具

    1.JDK命令行工具 Java开发人员肯定都知道JDK的bin目录有“java.exe”,"javac.exe"这两个命令行工具,但并非所有程序员都了解过JDK的bin目录之中其他 ...

  8. Xamarin引用第三方包错误解决方法

    http://www.cnblogs.com/ThenDog/p/7623720.html

  9. FFmpeg备忘录

    av_dup_packet函数 av_dup_packet会为destruct指针为av_destruct_packet_nofree的AVPacket新建一个缓冲区,将原有的缓冲区数据拷贝至新缓冲区 ...

  10. [INet] WebSocket 协议中的数据收发过程

    WebSocket 和 HTTP 相似,只是一个应用层协议,对下层透明,所以不涉及 TCP/IP. 由于浏览器支持了 WebSocket,所以在用 JS 写客户端的时候,是无需考虑数据的编码解码的. ...