题目链接:http://ac.jobdu.com/problem.php?pid=1040
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
//
// 1040 Prime Number.cpp
// Jobdu
//
// Created by PengFei_Zheng on 12/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#define max_size 1000010
using namespace std; bool prime[max_size]; void init(){
memset(prime,,sizeof(prime));
prime[] = false;
prime[] = false; int x = sqrt(max_size) + ; for(int i = ; i < x ; i++){ if(prime[i] == true ){
for(int j = i + i ; j < max_size ; j += i)
prime[j] = false ;
}
}
} int main(){
init();
int k;
while(scanf("%d",&k)!=EOF){
int nums = ;
for(int i = ; i < max_size ; i ++){
if(prime[i] == true){
nums++;
if(nums==k){
printf("%d\n",i);
break;
}
}
}
}
return ;
}
/**************************************************************
Problem: 1040
User: zpfbuaa
Language: C++
Result: Accepted
Time:10 ms
Memory:2496 kb
****************************************************************/