1096. Consecutive Factors (20)

来源:互联网 发布:淘宝店卖什么好呢 编辑:程序博客网 时间:2024/06/08 06:11

题目:

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;}