Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 1990 Accepted Submission(s): 837
import java.math.BigInteger; import java.util.Scanner; public class Main { static int vis[] = new int[1010]; static int p[] = new int[1010]; static BigInteger a[] = new BigInteger[110]; static void getp() { for(int i = 0; i < 1010; i++) vis[i] = 0; vis[1] = 1; for(int i = 2; i <= 1000; i++) { if(vis[i] == 0) for(int j = i * i; j <= 1000; j += i) { vis[j] = 1; } } int tp = 0; for(int i = 1; i <= 1000; i++) { if(vis[i] == 0) p[tp++] = i; } } public static void main(String[] args){ Scanner cin = new Scanner(System.in); getp(); a[0]=BigInteger.valueOf(1); for(int i=1;i<=100;i++) { a[i] = a[i-1].multiply(BigInteger.valueOf(p[i-1])); } int t = cin.nextInt(); while(t-- > 0) { BigInteger x; x = cin.nextBigInteger(); // for(int i = 0; i <= 10; i++){ // System.out.println(a[i]); // } if(x.compareTo(BigInteger.valueOf(6)) < 0){ System.out.println("2"); continue; } for(int i=0;i<=100;i++) { if(a[i].equals(x)){ System.out.println(a[i]); break; } else if(a[i].compareTo(x) > 0) { System.out.println(a[i-1]); break; } } } } }
原文:http://www.cnblogs.com/handsomecui/p/5523040.html