首页 > 代码库 > URAL 1086 Cryptography
URAL 1086 Cryptography
打质数表,记得很早之前优化过,但是忘了……
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。