PAT甲1096. Consecutive Factors (20)

原创 2018年04月16日 21:24:09

1.注意在2~(根号N+1)之间无解的话,输出N;

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std;

int main()  
{       
    int fac[100010];
    int N;
    scanf("%d",&N);
    int temp=N;
    int num=0;
    int max=0,maxindex=0,minf=N,minindex=N;;
    int sqr=sqrt(N*1.0);
    int d;
    for(int i=2;i<=sqr;i++)
    {
        d=i;
        while(N%d==0)
        {
            if(d<minf)minf=d;
            num++;
            N=N/d;
            if(num>max)
            {
                max=num;
                maxindex=d;
            }
            d++;
        }
        num=0;
        N=temp;
    }
    if(max==0)
    {
        printf("1\n");
    }
    else
    {
        printf("%d\n",max);
    }
    if(max<=1)
    {
        printf("%d",minf);
    }
    else if(max>1)
    {
        while(max>0)
        {
            printf("%d",maxindex-max+1);
            max--;
            if(max!=0)printf("*");
        }
    }
    else if(max==0)
    {
        printf("%d",temp);
    }

    printf("\n");
    system("pause");
    return 0;
}

PAT1096--浙大2015机试题--Consecutive Factors (20)

有点暴力的算法
  • grooowing
  • grooowing
  • 2015-03-21 23:02:12
  • 1834

PAT (Advanced Level) 1096. Consecutive Factors (20) 连续质因数

Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam...
  • tuzigg123
  • tuzigg123
  • 2015-07-31 21:16:23
  • 1421

PAT A 1096. Consecutive Factors (20)

题目 Among all the factors of a positive integer N, there may exist several consecutive numbers. For ...
  • xyzchenzd
  • xyzchenzd
  • 2015-04-01 13:47:52
  • 1127

1096. Consecutive Factors (20)

题目如下: Among all the factors of a positive integer N, there may exist several consecutive numb...
  • xyt8023y
  • xyt8023y
  • 2015-08-18 19:15:25
  • 1237

【PAT】1096. Consecutive Factors (20)

Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam...
  • realxuejin
  • realxuejin
  • 2015-10-08 22:10:13
  • 547

[PAT]1096. Consecutive Factors (20)

#include #include #include #include #include #include #include #include #include #include ...
  • rjq235
  • rjq235
  • 2015-10-04 15:05:22
  • 136

PAT 1096. Consecutive Factors (20)

#includeint begin, end, length, maxbegin, maxend, maxlength;int main(){ long long num; long ...
  • andyyang0212
  • andyyang0212
  • 2015-04-06 17:47:13
  • 459

pat 1096. Consecutive Factors

原题链接:https://www.patest.cn/contests/pat-a-practise/1096 1096. Consecutive Factors (20) ...
  • tt_twilight
  • tt_twilight
  • 2017-04-15 19:53:59
  • 115

PAT|1096. Consecutive Factors

PAT
  • sinat_35205772
  • sinat_35205772
  • 2016-09-08 15:38:11
  • 102

PAT(甲) Consecutive Factors (20)

题目描述 Among all the factors of a positive integer N, there may exist several consecutive numbers. F...
  • u011212549
  • u011212549
  • 2017-02-16 18:14:10
  • 65
收藏助手
不良信息举报
您举报文章:PAT甲1096. Consecutive Factors (20)
举报原因:
原因补充:

(最多只允许输入30个字)