题目地址

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<2
​31
​​ ).

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
567

作者: CHEN, Yue
单位: 浙江大学
时间限制: 400 ms
内存限制: 64 MB
代码长度限制: 16 KB

#include <iostream>
#include <vector>
#include<algorithm>
#include <cmath>
#include<map>
#include<cstring>
#include<queue>
#include<string>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn=100010,inf=100000000;
ll n;int cnt;vector<int>v,res;
int main(){
    cin>>n;ll len=0,left=-1;
    ll sqr=sqrt(n*1.0);bool flag=0;
    for(int i=2;i<=sqr;i++){
        ll temp=1;
        for(int j=i;j<=sqr;j++){
            temp*=j;
            if(n%temp!=0) break;        //找最长的可以被n整除的序列;
            if(j-i+1>len){
                left=i;len=j-i+1;
            }
        }
    }
    if(len==0) {
        cout<<1<<endl<<n;return 0;
    }
    cout<<len<<endl;
    for(int i=left;i<left+len;i++){
        if(i!=left)cout<<"*";
        cout<<i;
    }
}