[Zhengqing] [1776] The Monk's Troubles 2 - Which Prime?

Problem Description

Loading...

Problem Analysis

You could say this problem was tailor-made for prime table generation…

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<math.h>
#include<string.h>
int main() {
	int n,i,j,m,a[10000];
	long long int k;
	memset(a,0,sizeof(a));
	for(k=2,j=0; k<104730; k++) {
		for(i=2; i<=sqrt(k); i++)
			if(k%i==0) break;
		if(i>sqrt(k))
			a[++j]=k;
	}
	while(scanf("%d",&n)!=EOF) {
		while(n--) {
			scanf("%d",&m);
			printf("%d\n",a[m]);
		}
	}
	return 0;
}

Problem link: ZZULI — Monk’s Troubles 2: Which Prime Is It?

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...