猜了一个结论,题面跟欧拉函数有关系。
1 import java.util.*; 2 import java.math.*; 3 import java.text.*; 4 import java.io.*; 5 6 public class Main { 7 8 public static void main(String[] args) { 9 Scanner cin = new Scanner(System.in); 10 int p[] = new int[1001]; 11 int prim[] = new int[1001]; 12 int i, j, num, t; 13 BigInteger n, temp; 14 BigInteger s[] = new BigInteger[201]; 15 num = 0; 16 for (i = 0; i <= 1000; i++) 17 p[i] = 0; 18 for (i = 2; i <= 1000; i++) { 19 if (p[i] == 0) { 20 prim[num++] = i; 21 for (j = i + i; j <= 1000; j += i) { 22 p[j] = 1; 23 } 24 } 25 } 26 s[0] = BigInteger.valueOf(prim[0]); 27 for (i = 1; i < 150; i++) { 28 temp = BigInteger.valueOf(prim[i]); 29 s[i] = s[i - 1].multiply(temp); 30 31 } 32 t = cin.nextInt(); 33 while (t > 0) { 34 n = cin.nextBigInteger(); 35 for (i = 1; i < num; i++) { 36 if (n.compareTo(s[i]) == -1) { 37 break; 38 } 39 } 40 System.out.println(s[i-1]); 41 t--; 42 } 43 } 44 }