文章
3
粉丝
5
获赞
2
访问
3.2k
#include<bits/stdc++.h>
int a[1000005];
int count1 = 0;
int maxn = 1, tag = 0;
//判断合数
bool judge(int n)
{
for (int i = 2; i <= (int)sqrt(n); i++)
if (n%i == 0)
if (n != 2)
return true;
return false;
}
//把合数存到数组a
void save(int n, int m)
{
for (int i = n; i <=m; i++)
if (judge(i))
{
a[count1] = i;
count1++;
}
}
void compare(int a[])
{
int m = 1;
for (int i = 0; i < count1; i++)
if (a[i + 1] - a[i] == 1)
m++;
else
{
if (m > maxn)
{
maxn = m;
tag = i;//连续合数的最后一个
}
m = 1;
}
}
//主函数
int main()
{
int n, m;
scanf("%d %d", &n, &m);
save(n, m);
compare(a);
for (int i = tag - maxn+1; i <= tag; i++)
{
printf("%d ", a[i]);
}
return 0;
}...
登录后发布评论
暂无评论,来抢沙发