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
- 5*6*7
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- int MAX = ,n,index;
- scanf("%d",&n);
- int m = sqrt(double(n));
- for(int i = ; i <= m ;++i)
- {
- int k = i;
- int tmp = n;
- while(tmp%k == )
- {
- tmp = tmp / k;
- ++k;
- }
- if(k - i > MAX)
- {
- MAX = k - i;
- index = i;
- }
- }
- if(MAX == )
- {
- printf("1\n");
- printf("%d\n",n);
- return ;
- }
- printf("%d\n",MAX);
- for(int i = index ;i < index + MAX;++i)
- {
- if(i == index)
- {
- printf("%d",index);
- }
- else
- {
- printf("*%d",i);
- }
- }
- printf("\n");
- }
1096. Consecutive Factors (20)的更多相关文章
- 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 ...
- PAT Advanced 1096 Consecutive Factors (20) [数学问题-因子分解 逻辑题]
题目 Among all the factors of a positive integer N, there may exist several consecutive numbers. For e ...
- PAT甲题题解-1096. Consecutive Factors(20)-(枚举)
题意:一个正整数n可以分解成一系列因子的乘积,其中会存在连续的因子相乘,如630=3*5*6*7,5*6*7即为连续的因子.给定n,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...
- PAT (Advanced Level) 1096. Consecutive Factors (20)
如果是素数直接输出1与素数,否则枚举长度和起始数即可. #include<cstdio> #include<cstring> #include<cmath> #in ...
- 【PAT甲级】1096 Consecutive Factors (20 分)
题意: 输入一个int范围内的正整数,输出它最多可以被分解为多少个连续的因子并输出这些因子以*连接. trick: 测试点5包含N本身是一个素数的数据,此时应当输出1并把N输出. 测试点5包含一个2e ...
- PAT甲级——1096 Consecutive Factors (数学题)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors ...
- PAT 1096 Consecutive Factors[难]
1096 Consecutive Factors (20 分) Among all the factors of a positive integer N, there may exist sever ...
- PAT 甲级 1096 Consecutive Factors
https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...
- PAT 1096. Consecutive Factors
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
随机推荐
- UIScrollView,contentOffset,contentInsert的各自特点和区别?
• UIScrollView是一个能够滚动的视图控件,可以用来展示大量的内容,并且可以通过滚动查看所有的内容 设置UIScrollView的contentSize属性,告诉UIScrollView ...
- Java中transient有何作用?
transient关键字用来防止序列化域.如果一个引用类型被transient修饰,则其反序列化的结果是null.基本类型则为0.如果引用类型时不可序列化的类,则也应该使用transient修饰,它在 ...
- 新手留言薄asp.net MVC 学习(适合新手学习)
以下是发布到IIS后的效果截图: 1)首页展示: 2)登录后台页面展示: 3)后台页面展示: 该项目源代码下载地址:http://files.cnblogs.com/files/f12-liugang ...
- POJ 1287 Networking (最小生成树)
Networking Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit S ...
- hdu 4669 模拟
思路: 主要就是模拟这些操作,用链表果断超时.改用堆栈模拟就过了 #include<map> #include<set> #include<stack> #incl ...
- 基础面试题——Javascript
1.介绍js的基本数据类型 Undefined.Null.Boolean.Number.String 2.js有哪些内置对象? 数据封装类对象:Object.Array.Boolean.Number ...
- C#实现自定义事件,用于监视变量变化
很多时候我们需要程序具有一种功能,就是当满足某一条件时触发某个动作,使用C#的事件机制就可以达到这个目的下面的例子是一个很好的演示. 这段代码实现了对一个变量的监视,一旦变量发生改变,就触发动作 定义 ...
- phpstorm使用svn爆出“cannot load supported formats” 的解决
从这 http://subversion.apache.org/packages.html 下载svn客户端二进制包后修改phpstorm配置中 svn的指向到你的svn可执行程序即可解决
- 验证证书的安装之外部用户PC
背景:使用一个域外的用户进行登录并验证 1. 用户登录浏览器下载CA证书或者证书链 2. 下载 3. 安装证书 4. ...
- 关于柯尼卡美能达bizhub250出现c2557错误解决方法
打印机出现c2557代码的操作方法 1. 按效用/计数器键 英文是(Utility/Counter) 2. 看到有检查细息(Check Detail) 3. ...