input | output |
---|---|
4 3 2 5 7 |
5 3 11 17 |
// Ural Problem 1086. Cryptography // Judgement result: Accepted // Submission Date: 10:51 16 Jan 2014 // Run Time: 0.812s // Memory used: 273KB // Language: GCC 4.7.2 C11 // // 版权所有(C)acutus (mail: acutus@126.com) // 博客地址:http://www.cnblogs.com/acutus/ // [解题方法] // 简单素数题,直接打表判断 #include<stdio.h> int a[16000]; void init() { int i, count, flag, j; flag = 1; count = 2; a[1] = 2; a[2] = 3; j = 5; while(1) { for(i = 2; i <= count; i++){ if(j % a[i] == 0) { flag = 0; break; } } if(flag){ count++; a[count] = j; } flag = 1; j += 2; if(count > 15000) break; } } void solve() { int n, N; init(); scanf("%d", &N); while(N--) { scanf("%d", &n); printf("%d\n", a[n]); } } int main() { solve(); return 0; }
原文:http://www.cnblogs.com/acutus/p/3522122.html