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)的更多相关文章

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

  2. PAT Advanced 1096 Consecutive Factors (20) [数学问题-因子分解 逻辑题]

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

  3. PAT甲题题解-1096. Consecutive Factors(20)-(枚举)

    题意:一个正整数n可以分解成一系列因子的乘积,其中会存在连续的因子相乘,如630=3*5*6*7,5*6*7即为连续的因子.给定n,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...

  4. PAT (Advanced Level) 1096. Consecutive Factors (20)

    如果是素数直接输出1与素数,否则枚举长度和起始数即可. #include<cstdio> #include<cstring> #include<cmath> #in ...

  5. 【PAT甲级】1096 Consecutive Factors (20 分)

    题意: 输入一个int范围内的正整数,输出它最多可以被分解为多少个连续的因子并输出这些因子以*连接. trick: 测试点5包含N本身是一个素数的数据,此时应当输出1并把N输出. 测试点5包含一个2e ...

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

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

  7. PAT 1096 Consecutive Factors[难]

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

  8. PAT 甲级 1096 Consecutive Factors

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

  9. PAT 1096. Consecutive Factors

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

随机推荐

  1. 【Android 界面效果27】利用ViewPager、Fragment、PagerTabStrip实现多页面滑动效果

    本文主要介绍如何利用ViewPager.Fragment.PagerTabStrip实现多页面滑动效果.即google play首页.新浪微博消息(at.评论.私信.广播)页面的效果.ViewPage ...

  2. iOS之block块

    Block块. 1.声明Block int (^myBlock)(int n) = ^(int num) 类型 (^名称)(需要传的参数)= ^(参数) 2 __block 变量 在block块中修改 ...

  3. 10个实用的但偏执的Java编程技术

    在沉浸于编码一段时间以后,你会渐渐对这些东西习以为常.因为,你知道的-- 任何事情有可能出错,没错,的确如此. 这就是为什么我们要采用"防御性编程",即一些偏执习惯的原因.下面是我 ...

  4. javaweb学习总结二十六(response对象的用法二 下载文件)

    一:浏览器打开服务器上的文件 1:读取服务器上面的资源,如果在web层,可以直接使用servletContext,如果在非web层 可以使用类加载器读取文件 2:向浏览器写数据,实际上是把数据封装到r ...

  5. xcode报错 has been modified since the precompiled header was built

    删除/Users/username/Library/Developer/Xcode/DerivedData/ModuleCache 下的所有文件

  6. 代码创建FlexibleSpaceBarButton(弹性空白)

    //1.创建toolbar左边的按钮,调用initWithTitle方法进行初始化 // UIBarButtonItem *extend = [[UIBarButtonItemalloc]initWi ...

  7. Linux apache日志分析常用命令汇总

    1.查看当天有多少个IP访问: awk '{print $1}' log_file|sort|uniq|wc –l 2.查看某一个页面被访问的次数: grep "/index.php&quo ...

  8. TortoiseSVN 更新时忽略指定文件夹

    命令行可以这么来svn update –set-depth=exclude 文件夹 那么TortoiseSVN客户端呢?在文件夹右键中的”更新至版本(U)”更新深度选”排除”,确定,搞定下次更新就不会 ...

  9. 用户体验测试(UE测试)

    用户体验测试(UE测试) 在测试周期早些时候就开始用户体验测试很明智.多数人往往会把UE测试放在最后,但UE测试可以揭示很多问题,如外观.字体.文本颜色.背景颜色.内容.布局等,还可以在测试周期尽可能 ...

  10. C#右键复制路径

    using System;//Environment using System.Windows.Forms; //add referece of System.Windows.Forms :DataF ...