用数组存,哪错了?
查看原帖
用数组存,哪错了?
754658
haha_hua楼主2024/7/17 20:31
#include<iostream>
#include<cstring>
using namespace std;
int book[100001];

int main(){
	memset(book,1,sizeof(book));
	int n;
	cin >> n;
	for(int i = 2; i <= 1000; i++)
	{
		for(int j = 2; j <= 100; j++)
		{
			book[i*j] = 0;
		}
	}
	int ans = 0;
	for(int i = 2; i <= 100001; i++)
	{
		if(book[i]) ans++;
		if(ans == n)
		{
			cout << i;
			return 0;
		}
	}
	
	
	return 0;
}
2024/7/17 20:31
加载中...