求助大佬
查看原帖
求助大佬
381370
jedi_5298楼主2021/1/28 15:23
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int L,k=0,a[10000],sum=0;
	cin >> L;
	for (int i = 0; i <= L; i++)//将0到L所有数存到数组
	{
		a[i] = i;
	}
	for (int i = 3; i <= L; i++)//将不是质数的数字所在位置替换成0
	{
		for (int j = 2; j < i; j++)
		{
			if (i%j == 0)
			{
				a[i] = 0;
			}
		}
	}

	for (int i=0; i <= L; i++)
	{
		
		if (a[i] != 0&&a[i]!=1 && sum <= L)//因为输入0,1输出0 所以不考虑
		{
			cout << a[i] << endl;
			k++;
		}
		sum += a[i];
	}
	cout << k;
	system("pause");
	return 0;
}
2021/1/28 15:23
加载中...