# 一、题目描述

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.

630

3
567

# 三、AC代码

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
int mx = 0;
long long i, j, N;
vector<int> ans;
scanf("%lld", &N);
for(i=2; i*i <= N; i++)   //题目要求最小序列，那么不可能有两个满足i*i>N的因子
{
int cnt = 0;    //连续因子的个数
long long sum = 1;  //连续因子的乘积
vector<int> tmp;
for(j=i; ; j++) //
{
sum *= j; //连续乘积
if(N%sum == 0)    //可以被整除
{
tmp.push_back(j);
cnt++;
}
else  //不能被整除，更新答案，退出循环
{
if(cnt > mx)    //更新答案
{
mx = cnt;
ans = tmp;
}
break;
}
}
}
if(mx == 0)   //N为素数
{
printf("1\n%d", N);
return 0;
}
printf("%d\n", mx);
for(int k=0; k<ans.size(); k++)
{
if(k==0)	printf("%d", ans[0]);
else	printf("*%d", ans[k]);
}
return 0;
}

• 点赞 1
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

陈xLヾ

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
08-22 360

©️2020 CSDN 皮肤主题: 1024 设计师:上身试试