回文素数

https://www.nowcoder.com/practice/4802faa9afb54e458b93ed372e180f5c?tpId=90&tqId=30793&tPage=1&rp=1&ru=%2Fta%2F2018test&qru=%2Fta%2F2018test%2Fquestion-ranking

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);
    }
}

 

posted @ 2019-05-13 09:48  LeeJuly  阅读(126)  评论(0)    收藏  举报