码迷,mamicode.com
首页 > 其他好文 > 详细

URAL 1086 Cryptography

时间:2014-08-26 07:26:35      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   for   ar   div   log   sp   

打质数表,记得很早之前优化过,但是忘了……

 1 import java.util.ArrayList;
 2 import java.util.List;
 3 import java.util.Scanner;
 4 
 5 public class P1086
 6 {
 7     private static final int MAXN = 200000;
 8     private static boolean isPrime[] = new boolean[MAXN];
 9     private static List<Integer> primeList = new ArrayList<>();
10 
11     public static void initPrimeList()
12     {
13         for (int i = 2; i < MAXN; i++)
14             isPrime[i] = true;
15         for (int i = 2; i < MAXN; i++)
16             if (isPrime[i])
17             {
18                 for (int j = 2; i * j < MAXN; j++)
19                     isPrime[i * j] = false;
20                 primeList.add(i);
21             }
22         //        System.out.println(primeList.size());
23     }
24 
25     public static void main(String args[])
26     {
27         initPrimeList();
28         try (Scanner cin = new Scanner(System.in))
29         {
30             while (cin.hasNext())
31             {
32                 int n = cin.nextInt();
33                 for (int i = 0; i < n; i++)
34                     System.out.println(primeList.get(cin.nextInt() - 1));
35             }
36         }
37     }
38 }

 

URAL 1086 Cryptography

标签:style   blog   color   java   for   ar   div   log   sp   

原文地址:http://www.cnblogs.com/gwhahaha/p/3936345.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!