题解 | #素数回文#
素数回文
https://www.nowcoder.com/practice/d638855898fb4d22bc0ae9314fed956f
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // 构造回文数 String str = "" + n; StringBuilder sb = new StringBuilder(); sb.append(str.substring(0, str.length()-1)); String num = "" + n + sb.reverse().toString(); long res = Long.parseLong(num); // 判断回文数是否是素数 for (long i=2; i*i <= res; i++) { if (res % i == 0) { System.out.println("noprime"); return; } } System.out.println("prime"); } }