回文素数
import java.util.*; public class Main{ public static boolean IsPrime(int x) { if (x == 0 || x == 1) return false; for (int i = 2; i <= x / 2; i++) if (x % i == 0) return false; return true; } public static boolean IsRevrse(int x) { int temp = 0,xs=x; while (x!=0) { temp = (temp * 10 + x % 10); x = x / 10; } return xs == temp ? true : false; } public static void main(String[] args){ Scanner in = new Scanner(System.in); int l=in.nextInt(); int r=in.nextInt(); int sum=0; for(int i=l;i<=r;i++){ if(Main.IsRevrse(i)&&Main.IsPrime(i)) sum++; } System.out.println(sum); } }
本文来自博客园,作者:LeeJuly,转载请注明原文链接:https://www.cnblogs.com/peterleee/p/10855005.html

浙公网安备 33010602011771号