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. BZOJ3289【莫队算法+树状数组+离散化】

    思路: 区间逆序数即是交换次数. 逆序数,可以用树状数组吧. 怎么处理区间变换的时候求逆序数啊.. 这里分成左边的增/删,右边的增/删 因为是按时序插入, 所以左边增,增一个数,计算:ans+=sun ...

  2. Untiy一些方法前特殊标签记录

    [ExecuteInEditMode] // Make code live-update even when not in play mode [ContextMenu("Execute&q ...

  3. plt

    设定X,Y轴的长度以及刻度的方法. import numpy as np import matplotlib.pyplot as plt data = np.arange(0,1.1,0.01) pl ...

  4. day03 System Math

  5. idea | gitee 码云

    https://blog.csdn.net/qq_32340877/article/details/81205547

  6. VS2015 : error LNK1168

    VC在重新生成Debug目录下的exe文件时,需要先删除原先的exe文件.但因为文件正在运行或是被锁定等原因,删除不了,于是出现 LNK1168错误.可以到任务管理器先将exe文件关闭,一个简单粗暴的 ...

  7. Tinghua Data Mining 5

    ID3 ID3算法倾向于分的很细的变量 C4.5加入分母为惩罚量

  8. 使用express+mongoDB搭建多人博客 学习(1) 安装blog工程

    一.安装 1.安装express npm install -g expressnpm install -g express-generator 2.用ejs做模板,新建blog工程express -e ...

  9. P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers

    题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人.然而,在任何一群朋友中 ...

  10. Semi-prime H-numbers

    题目描述形如4n+1的数被称为“H数”,乘法在“H数”集合内为封闭的.因数只有1和本身的数叫“H素数”(不包括1),其余叫“H合数”.一个“H合成数”能且只能分解为两个“H素数”.求0·h内的“H合成 ...