http://www.patest.cn/contests/pat-a-practise/1096

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

此题是2015年春季的研究生入学考试复试时的机试题,链接 http://www.patest.cn/contests/graduate-entrance-exam-2015-03-20此题不难,但是很多人没拿到分数,因为没有想到最简单的方法:暴力遍历。针对一个已确定是Factor的数tempfactor,进行如下处理:
while(num%tempfactor==0) templen++,num/=tempfactor,tempfactor++;
if(templen>maxlen) maxlen=templen,maxfactor=factors[i];
 #include<stdio.h>
#include<math.h> int main()
{
int N=;
scanf("%d",&N);
if(N== || N== || N==) {printf("1\n%d",N);return ;} int num=(int)sqrt(N),len=,factors[]={};
for(int i=;i<=num;i++) if(N%i==) factors[len]=i,len++;
factors[len]=N,len++; int maxlen=,maxfactor=N;
int templen=,tempfactor=;
for(int i=;i<len;i++)
{
num=N,tempfactor=factors[i],templen=;
while(num%tempfactor==) templen++,num/=tempfactor,tempfactor++;
if(templen>maxlen) maxlen=templen,maxfactor=factors[i];
} printf("%d\n",maxlen);
for(int i=;i<maxlen;i++)
{
if(i) printf("*%d",maxfactor);
else printf("%d",maxfactor);
maxfactor++;
}
return ;
}

PAT (Advanced Level) Practise - 1096. Consecutive Factors (20)的更多相关文章

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

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

  2. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  3. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  4. PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...

  5. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

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

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

  7. 1096. Consecutive Factors (20)

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

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

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

  9. 1077. Kuchiguse (20)【字符串处理】——PAT (Advanced Level) Practise

    题目信息 1077. Kuchiguse (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The Japanese language is notorious f ...

随机推荐

  1. npm切换到淘宝镜像

    1. npm简介 1.1.说明:npm(node package manager)nodejs的包管理器,用于node插件管理(包括安装.卸载.管理依赖等): 1.2.使用npm安装插件:命令提示符执 ...

  2. 算法学习--Day7

    今天多做一些杂题练习一下. 第一题: 题目描述 在情报传递过程中,为了防止情报被截获,往往需要对情报用一定的方式加密,简单的加密算法虽然不足以完全避免情报被破译,但仍然能防止情报被轻易的识别.我们给出 ...

  3. CodeForces 363D 【二分+贪心】

    思路: 一开始是没有办法贪心的,但是答案是可以二分的,因为窝能买k辆车的话,窝就一定能买k-1辆车:而且我最好就是拿手上钱较多的那些人去买价格便宜的车,这样肯定是能买到最多的车,而且花的少,因为对于要 ...

  4. 3d工具收集

    Poser 是Metacreations公司推出的一款三维动物.人体造型和三维人体动画制作的极品软件.用过Poser 2与Poser 3的朋友一定能感受到Poser的人体设计和动画制作是那么的轻松自如 ...

  5. IT兄弟连 JavaWeb教程 Servlet会话跟踪 Session常用方法

    ●  public Object getAttribute(String name) 该方法返回在该session会话中具有指定名称的对象,如果没有指定名称的对象,则返回null. ●  public ...

  6. Java 虚拟机(Java Virtual Machine)

    Java 编译器将 Java 程序编译成虚拟机能够识别的二进制代码,这种代码称为字节码(Bytecode).字节码就是虚拟机的机器指令,它与平台无关,有统一的格式,不依赖于具体的硬件环境,只运行在 J ...

  7. 笔记-JavaWeb学习之旅6

    表格标签: table:定义表格 width :宽度 border:边框 cellpadding:定义内容和单元格的距离了 cellspacing:定义单元格之间的距离 bgcolor:背景色 tr: ...

  8. linux 系统运行级别(转)

    Linux系统有7个运行级别(runlevel)运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆运行级别2:多 ...

  9. day03 内部类

  10. 抛出异常-throws和throw

    package com.mpp.test; import java.util.Scanner; public class TryDemoFour { public static void main(S ...