【PAT】1096. Consecutive Factors

来源:互联网 发布:进销存数据库设计 编辑:程序博客网 时间:2024/05/01 18:52
#define LOCAL#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>using namespace std;typedef long long ll;bool isprime(int x){    for(int i=2;i*i<=x;i++){        if(x%i==0) return false;    }    if(x==0 || x==1) return false;    else    return true;}int main(){    #ifdef LOCAL        freopen("data.in","r",stdin);        freopen("data.out","w",stdout);    #endif // LOCAL    ll n;    scanf("%lld",&n);    ll sqr=(ll)sqrt(1.0*n),ans=0,len=0;    for(ll i=2;i<=sqr;i++){        int alen=0;        ll res=i;        int d=i+1;        while(n%res==0&&res<=n){            res*=d;            d++;alen++;        }        if(alen>len){            ans=i;len=alen;        }    }    if(len==0) printf("1\n%lld",n);    else{        printf("%lld\n",len);        for(ll i=0;i<len;i++){            printf("%lld",ans+i);            if(i<len-1)printf("*");        }    }    return 0;}

0 0
原创粉丝点击