Prime Palindromes easy

import java.io.BufferedReader;
import java.io.InputStreamReader;

 class test {

    public static boolean ispallin(String n)
{
    StringBuffer a = new StringBuffer(n);
    
   
            
if(n.equals(a.reverse().toString()))
{

    return true;
}
    return false;
    
}
   public static boolean isprime(int n)
   {
       if(n==1)
       {
           return false;
       }
       if(n==2)
       {
           return true;
       }
       for(int i =2;i<=Math.sqrt(n);i++)
       {
           if(n%i==0)
           {
               return false;
           }
           
           
       }
       return true;
       
       
   }
    public static void main(String[] args)throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     
        
        int n = Integer.parseInt(br.readLine());
        
        for(int m=n;m<=1000000;m++)
        {
if(m>3&&m%2==0)
{
    continue;
}

        String str;
        str = String.valueOf(m);
        
       
            if(ispallin(str) && isprime(m))
            {
                System.out.println(m);
                break;
            }
            
            
        }
        
    }
}

why is it giving wrong answer am i missin something here ??

sorry… it was a very silly mistake of me
needed to remove the condition of m<=1000000 from the for loop got an ac finally :slight_smile:

One mistake that i found:

Input:99000

Expected output: 1003001 (mostly)

Your ouput: Nothing! :open_mouth:

See this.

Hope this helps! :slight_smile:

1 Like

yees got that one :slight_smile: thnx…!

1 Like