首页 > ACM题库 > 九度OJ > 九度-1040-Prime Number[解题代码]
2013
12-12

九度-1040-Prime Number[解题代码]

题目来源:2008年上海交通大学计算机研究生机试真题

题目描述:

Output the k-th prime number.

输入:

k≤10000

输出:

The k-th prime number.

样例输入:
3
7
样例输出:
5
17

cpp 代码如下:
#include <math.h>
#include <string.h>
#include <stdio.h>
using namespace std;
int max1 = 105000;
bool isPrim[105000];
int arr[10001];
int main() {
	int n = 324;
	memset(isPrim, true, sizeof(isPrim));
	for(int i=2; i<=n; i++) if(isPrim[i]) for(int j=i; i*j < max1; j++) isPrim[i*j] = false;
	int cnt = 1,t;
	for(int i=2; i<max1; i++) if(isPrim[i]) arr[cnt++] = i;
	while(scanf("%d",&t) != EOF) printf("%d\n",arr[t]);
	return 0;
}

/**************************************************************
	Problem: 1040
	User: coder
	Language: C++
	Result: Accepted
	Time:10 ms
	Memory:1164 kb
****************************************************************/


  1. Often We don’t set up on weblogs, but I would like to condition that this established up really forced me individually to do this! considerably outstanding publish