Consecutive Factors (20)
这道题主要考数学.
要求找到可以除的最长连续序列,所以找个可以除尽的就可以了。sqrt(n) 这个地方不知道必要不必要,但是可以略微提高下效率吧。翻译有问题,以前做过这个但是,再看一遍题意还是没有了解清除
代码如下:
#include <stdio.h>
#include <math.h>
int main()
{
long long n;
scanf("%d",&n);
int Max = 0;
int first = 0;
int i;
for(int i = 2;i<=sqrt(n)+1;i++)
{
int tmp = n;
int count = 0;
int start = i;
while(tmp % start ==0)
{
tmp/=start;
count++;
start++;
}
if(count>Max)
{
Max = count;
first = i;
}
}
if(Max == 0)
{
printf("1\n%d",n);
return 0;
}
printf("%d\n",Max);
printf("%d",first);
for(int i = first+1;i<first+Max;i++)
{
printf("*%d",i);
}
}