54分求助
查看原帖
54分求助
981005
KipperLee楼主2023/7/28 14:19

评测结果不是AC就是RE,代码如下:

#include <iostream>
#include <cstring>
using namespace std;

int cnt[1000005];
bool f[1000005];

int main()
{
	memset(f, true, sizeof(f));
	f[0] = f[1] = false;
	
	int m, n;
	cin >> m >> n;
	
	for (int i = 2; i <= n; i++)
	{
		if (f[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				f[j] = false;
			}
		}
	}
	
	for (int i = 1; i <= n; i++)
	{
		cnt[i] = cnt[i - 1] + f[i];
	}
	
	for (int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		
		if (x < 1 || y > n)
		{
			cout << "Crossing the line" << endl;
			continue;
		}
		
		cout << cnt[y] - cnt[x - 1] << endl;
	}
	
	return 0;
}
2023/7/28 14:19
加载中...