You are not logged in. Please login at www.codechef.com to post your questions!

×

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 ??

asked 08 Jul '13, 13:22

zargus's gravatar image

2★zargus
17662136
accept rate: 0%

edited 08 Jul '13, 13:27

kunal361's gravatar image

4★kunal361
6.0k133272


One mistake that i found:
Input:99000
Expected output: 1003001 (mostly)
Your ouput: Nothing! :O
See this.
Hope this helps! :)

link

answered 08 Jul '13, 13:45

sunny_patel's gravatar image

2★sunny_patel
1.3k31025
accept rate: 19%

1

yees got that one :) thnx..!

(08 Jul '13, 13:48) zargus2★

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 :)

link

answered 08 Jul '13, 13:41

zargus's gravatar image

2★zargus
17662136
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,070

question asked: 08 Jul '13, 13:22

question was seen: 764 times

last updated: 08 Jul '13, 13:48