题目:
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
解答:
//A1096
#include<cstdio>
#include<cmath>
int main(){
int n;
scanf("%d",&n);
int first=0,len,maxlen=0,j,tempn;
for(int i=2;i<=sqrt(n);i++){
j=i,tempn=n,len=0;
while(tempn%j==0){
len++;
tempn/=j;
j++;
}
if(maxlen<len){
first=i;
maxlen=len;
}
}
if(maxlen==0){
printf("1\n%d",n);
}else {
printf("%d\n",maxlen);
for(int i=0;i<maxlen;i++){
if(i!=0)printf("*");
printf("%d",first+i);
}
}
return 0;
}