PAT——A1096 Consecutive Factors

题目链接:

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    scanf("%lld",&n);
    int sqr=(ll)sqrt(1.0*n);
    int first=n;
    int maxlength=0;
    for(int i=2;i<=sqr;i++)
    {
       int temp=n;
       int start=i;
       while(temp%start==0)
       {
           temp/=start;
           start++;
       }
       if(start-i>maxlength)
       {
           maxlength=start-i;
           first=i;
       }
    }
    if(maxlength==0)
    {
        cout<<1<<endl;
        cout<<n<<endl;
    }
    else
    {
        cout<<maxlength<<endl;
        cout<<first;
        for(int i=1;i<maxlength;i++)
        {
            cout<<'*'<<first+i;
        }
        cout<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42232118/article/details/82290244