CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Prime Palindromes

Prime Palindromes

Problem code: PRPALIN

  • Submit
  • All Submissions

All submissions for this problem are available.

An integer is said to be a palindrome if it is equal to its reverse. For example, 79197 and 324423 are palindromes. In this task you will be given an integer N, 1 N 1000000. You must find the smallest integer M N such that M is a prime number and M is a palindrome.

For example, if N is 31 then the answer is 101.

Input

A single integer N, (1 N 1000000), on a single line.

Output

Your output must consist of a single integer, the smallest prime palindrome greater than or equal to N.

Example

Input:
31
Output:
101

Author: admin
Date Added: 28-07-2009
Time Limit: 1 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

why can't i submit my

piman314 @ 20 Aug 2009 06:54 AM
why can't i submit my solution?

Why cant  I view the problem

Shitij @ 29 Sep 2009 05:39 PM

Why cant  I view the problem ??

There is something wrong with

admin @ 29 Sep 2009 07:33 PM

There is something wrong with the test cases. This will be fixed in a few days.

M is less than or equal to N.

jcomeau_ictx @ 1 Jan 2010 08:39 AM

M is less than or equal to N. I had to find that out by trial-and-error. Why doesn't your software permit you to enter numeric symbols? Since most of the problems are numeric in nature, this is quite a handicap. I notice you have fixed some of them, though. Thank you.

how to remove the time limit

abhijeetgoel @ 2 Jan 2010 10:48 AM

how to remove the time limit exceeded error in this program.............

You must find the smallest

Geniusguy @ 2 Jan 2010 02:22 PM

You must find the smallest integer M N such that M is a prime number and M is a palindrome.

can u please explain the meaning of underlined text ! ! !

i.e how M is realted to N ? ? ? ?

It should say M >= N, as John

triplem @ 22 Jan 2010 11:00 AM

It should say M >= N, as John pointed out in the comment 2 above yours.

yeah. . i got it. . .nyways

Geniusguy @ 4 Jan 2010 01:55 PM

yeah. . i got it. . .nyways thnx fr replyin Stephen ! !  !

@Stephen It should say M >= N

vector9x @ 22 Jan 2010 10:05 AM

@Stephen

It should say M >= N to be coherent with the example.

Whoops, thanks. Fixed.

triplem @ 22 Jan 2010 11:00 AM

Whoops, thanks. Fixed.

@ALL anytest case/s which

SumitRathi @ 13 Feb 2010 11:02 PM

@ALL

anytest case/s which takes time??

Hey all, My program is

Kanishk @ 16 Apr 2010 07:11 PM

Hey all,

My program is running for small test cases but as the value is increased it is unable to show the result.The best that it went upto was around 98000.Someone please rectify the mistake.

 

Here's the code...

 

 

 

 

#include<stdio.h>

 

int main()

{

unsigned long int n,rev,i,j,k,m=0;

unsigned long int fl=1;

rev=0;

 

printf("Enter the number:");

scanf("%d",&n);

 

for(i=n;;i++)

{

fl=1;

for(j=2;j<i/2;j++)

{

if(i%j==0)

{

fl=0;

}

}

 

 

if(fl==1)

{

m=i;

while(m>0)

{

k=m%10;

rev=(rev*10)+k;

m/=10;

}

 

if(rev==i)

{

break;

}

else

rev=0;

}

}

 

 

printf("The required number is: %d",rev);

 

return 0;

}

@admin............plz check

vikasssa @ 29 May 2010 05:56 PM

@admin............plz check the sol

http://www.codechef.com/viewsolution/246369

i m getting TLE ........but it is working fine on my system

HELP HELP HELP

@Admin: I've tried a lot to

manjotpahwa @ 1 Jun 2010 01:26 PM

@Admin:

I've tried a lot to reduce the time, I've managed to reduce the time to check if the number is prime to a bre minimum, I've taken tth least time to compute if its a palindrome or not. Can you please tell me which part is taking time, because I've tried tor educe all parts. My code:

http://www.codechef.com/viewsolution/247098

Thank you.

@vikas - your code doesn't

triplem @ 1 Jun 2010 01:43 PM

@vikas - your code doesn't work for the sample input.

@Manjot - try input 99000.

 

i removed that

vikasssa @ 1 Jun 2010 10:04 PM

i removed that error........and also tried to optimise the code to a great extent............then also i am getting TLE.......plz tell me .........where my code is lacking ..........plz help me.......this is optimised one.....

http://www.codechef.com/viewsolution/247548 plz check it..........

sir..plz check my

vikasssa @ 6 Jun 2010 02:45 PM

sir..plz check my solution.........and tell me the bug in  solution,,,,,,,,,,http://www.codechef.com/viewsolution/247548

http://www.codechef.com/views

vikasssa @ 8 Jun 2010 12:05 PM

http://www.codechef.com/viewsolution/247548

@admin -> its really

vikasssa @ 12 Jun 2010 05:20 PM

@admin -> its really frustrating...........so many TLEs.......

may i know that....which part of my code or for which input case my code is taking such a long time???????

any hint ??????????????

my code->http://www.codechef.com/viewsolution/268644

thank you.............

i was doing the stupid

vikasssa @ 14 Jun 2010 03:53 PM

i was doing the stupid mistake........but finally goi it accepted...........

thnx for not answering my questions...........

Can anyone tell what must be

anish7766 @ 27 Jun 2010 05:11 PM

Can anyone tell what must be the output for 99000.....

@Anish 1003001 is the output

javadecoder @ 27 Jun 2010 07:20 PM

@Anish 1003001 is the output for 99000

@Piyush:- Yep got it...

anish7766 @ 28 Jun 2010 11:38 AM

@Piyush:- Yep got it... Thanks man....

Hello admin, I'm not

mtk @ 14 Jul 2010 11:26 AM

Hello admin,

I'm not understanding why I'm getting the wrong answer, I have checked for the boundary numbers too.

What about single digit prime number? Please reply , where my code is giving the wrong answer.

please give me a hint atleast, as it is not a contest problem now.

 

Thanks...

I got it correct.... But

mtk @ 14 Jul 2010 12:22 PM

I got it correct....

But before, I was using sieve of Erathmosis method to generate prime upto 1000000 and then storing the palindromes in an array. This was giving me a SIGGEV error.

Then I just changed the code that had only the valid prime palindromes.. and this worked ... But I didn't get why the previous code was giving that particular error ????

Thanks

what will be the output if

nikhil belchada @ 7 Aug 2010 12:13 PM

what will be the output if number is greater then 98689

what should be prined after

nikhil belchada @ 7 Aug 2010 12:26 PM

what should be prined after 98689 because the answer is 1003001 which is less tha 1000000.....

pls reply.....

thanx.

The problem statement just

triplem @ 7 Aug 2010 12:27 PM

The problem statement just says N is less than a million, it doesn't say your answer must be.

please check my code why it

nikhil belchada @ 7 Aug 2010 12:51 PM

please check my code why it is giving wrong answer

http://www.codechef.com/viewsolution/301604

thanx ...

I m nt able to submit my

Rounak Tibrewal @ 12 Aug 2010 07:52 PM

I m nt able to submit my code.....Its showing "Wrong Login & Password"

can any one please tell me

nikhil belchada @ 17 Aug 2010 04:43 PM

can any one please tell me where i am going wrong

http://www.codechef.com/viewsolution/301604

please reply....

Whats wrong with my code can

nikhil belchada @ 31 Aug 2010 10:55 PM

Whats wrong with my code can any one tell me please i submitted lot of solution...

http://www.codechef.com/viewsolution/317757

please help...

Hello Admin, I am getting

njmbo @ 5 Sep 2010 04:45 PM

Hello Admin,

I am getting Runtime Error.But am not able to find out why.!

I take input in a string type and first check for palindrome then check if that palindrome is a prime or not.

Please help.!

My code is:

#include<iostream>

#include<math.h>

#include<string>

using namespace std;

string s;int c=9;string str;

int palindrome()

{

int k=0;int count=0;

while(1)

{

if(s[count]=='0')

count++;

else

break;

}

 

int i=count;//cout<<"count"<<(31-count)/2+count;

while(i<=((c-count)/2+count))

{

if(s[i]!=s[c-i+count])

{

k=1;

break;

}

i++;

}

if(k==1)

{return 1;}

else

return 0;

}

 

int increment()

{

 

if(s[c]=='9')

{

s[c]='0';c--;

increment();

}

else

{

 

s[c]=(char)((int)s[c]+1);//cout<<"h";//cout<<s[c];

return 0;

}

}

int prime()

{

int k=0;int count=0;

while(1)

{

if(s[count]=='0')

count++;

else

break;

}

int i=count;

int number=0;

//cout<<"count="<<count;

while(i<=c)

{

number=number*10+ (((int)s[i])-48);

i++;

}

 

int g=0;

int root=pow(number,0.5);

for(int ii=2;ii<root;ii++)

{

if(number%ii==0)

{

g=1;break;

}

}

if(g==1)

return 0;

 

else return number;

}

int main()

{

 

cin>>str;int m=str.length()-1;int i=c;

//cout<<c;

 

for( i=c;i>c-str.length();i--)

{s[i]=str[m];m--;}

for(;i>=0;i--)

s[i]='0';

while(1)

{

int chk=palindrome();

if(chk==0)//palindrome

{

 

int p=prime();

if(p!=0)

{

cout<<p;

break;//found the prime

}

 

}

 

int tt=increment();c=9;

 

 

}

system("pause");

return 0;

}

I got it!Thanks!

njmbo @ 5 Sep 2010 04:58 PM

I got it!Thanks!

1s for this problem is

avinash1 @ 29 Oct 2010 10:10 AM

1s for this problem is calculated for single N or running the code several times for different N's?

This is explained in the FAQ.

triplem @ 29 Oct 2010 11:20 AM

This is explained in the FAQ. In this case, each input file only contains one N, so the time limit only applies to that one N.

I am getting a runtime(other)

rampage @ 12 Dec 2010 05:25 PM

I am getting a runtime(other) error.According to the FAQ it is generally caused by using too much memory. But I don't think that's the problem this time around. Its giving the correct answer for all test cases that I checked on my machine.

Please take a look and point out the mistake

http://www.codechef.com/viewsolution/398600

hello admin plz check my code

eagleye @ 5 Jan 2011 01:54 PM

hello admin plz check my code plz

#include<stdio.h>

# define max 1000000

int main()

{

int n,i,num,temp,count=0,j,remainder=0,sum=0;

printf("enter initial limit:");

scanf("%d",&n);

for(i=n;i<max;i++)

{

num=temp=i;

while(num>0)

{

remainder=num%10;

num=num/10;

sum=sum*10+remainder;

}

 

if(sum==temp)

{

for(j=2;j<temp;j++)

{

if(temp%j==0)

count=1;

}

if(!count)

{

printf("%dn",temp);

break;

}

}

sum=0;

count=0;

}

return 0;

}

it is finely working.plz help

eagleye @ 5 Jan 2011 01:56 PM

it is finely working.plz help i can't figure out what is  the problem in this code.codechef compiler is giving wrong answer

Please read the FAQ.

triplem @ 5 Jan 2011 02:01 PM

Please read the FAQ.

/sources/tested.c: In

bratibiswas @ 21 Feb 2011 10:32 AM

/sources/tested.c: In function 'main': /sources/tested.c:7: error: expected ')' before ';' token

 

 

WTF....?

what is the problem in my program?

and after correction it is showing time limit exceed......


can nebody tell wats wrong

bishes_kh @ 27 Feb 2011 12:06 AM

can nebody tell wats wrong with my program? a runtime error is encountered.

#include<stdio.h>
#include<math.h>
//#include<conio.h>
int prime(long int num)
{
int i;
if(num==2) return(1);
else if(num%2==0) return(0);
else
{for(i=3;i<(sqrt(num));i=i+2)
{
if(!(num%i))
return(0);
}
return(1);}
}
int palin(long int rev,long int num)
{
long int temp=num;
while(num>0)
{rev=(rev*10)+(num%10);
num=num/10;}
if(temp==rev)
return(1);
else
return(0);
}

void main()
{
int pc,pac=0,rev=0;
long int num;
scanf("%ld",&num);
while(!pac)
{
pc=prime(num);
if(pc)
{pac=palin(rev,num);
if(pac)
printf("%ld",num);
}
num+=1;
}
//getch();
}

plz help me . y this code is

km_rama @ 31 Mar 2011 10:11 AM

plz help me . y this code is printing garbage value in TURBOC

 

int main()

{

unsigned long int i=1000000;

printf("nnnn  hello =%ld",i);

return 0;

}

@Raman Tripathi the format

admin @ 31 Mar 2011 07:42 PM

@Raman Tripathi the format specifier '%ld' is wrong, chk the link. '%ld' is for signed long integer and not for unsigned.

There's no max limit

harish_8080 @ 19 Apr 2011 01:40 AM

There's no max limit specified in problem, but from (1 N 1000000) we assume that max limit is 1000000, but answers will be tested beyond this case.

I've also found a list of Palindromic Primes, you can check your answers are correct or not from here:

http://oeis.org/A002385/b002385.txt

Hey all, My program is

surojiit @ 30 Apr 2011 09:32 AM

Hey all,

My program is running for small test cases but as the value is increased it is unable to show the result.The best that it went upto was around 98000.Someone please rectify the mistake.

 

Here's the code...

#include<cstdio>

#include<iostream>

using namespace std;

int main()

{unsigned int flag=1,num,digit;

unsigned int n,b;



cin>>b;

for(unsigned int i=b;i<1000000;i++)

{

flag=1;

for(unsigned int j=2;j<i;j++)

{

if(i%j==0)

{

flag=0;

break;

}

} if(flag==1)

{

// cout << i << " ";

num=i;

n=i;

unsigned int rev=0;

do{

digit=num%10;

rev=rev*10+digit;

num=num/10;

}while(num!=0);

if(n==rev)

{cout<<n<<" ";break;}

}

}   system("pause");

return 0;

}

hey i dunno why for 99000 or

hungrycoder @ 18 Jun 2011 12:26 AM
hey i dunno why for 99000 or more my code is not working although i am using datatype long long int....please help

#include int Palin(long long

hungrycoder @ 18 Jun 2011 12:27 AM
#include int Palin(long long int n) { long long int b,temp,rem,result; result=0; b=n; do { rem=n%10; n=n/10; result=result*10+rem; } while (n!=0); // printf("%d ",result); if((result-b)==0) return 1; else return 0; } int prime(long long int n) { long long int i,flag; flag=0; for(i=2;i<=n/2;i++) { if(n%i==0) { flag=1; break; } } if (flag==1) return 0; else return 1; } int main() { long long int n,flap,t,s,result; //unsigned long int n; flap=0; scanf("%lld",&n); do { t=Palin(n); s=prime(n); n++; if(t==1&&s==1) flap=1; } while(flap!=1); result=n-1; printf("%lldn",result); return 0; }

the link is

hungrycoder @ 18 Jun 2011 12:29 AM
the link is http://www.codechef.com/viewsolution/576034

@hungrycoder::Try to think

javadecoder @ 18 Jun 2011 03:20 AM
@hungrycoder::Try to think for the numbers in the range 100000-999999 ;)

@javadecoder i dont

hungrycoder @ 18 Jun 2011 10:57 AM
@javadecoder i dont understand why instead of using long long int it is not able to show the result....

no no sry....its showing the

hungrycoder @ 18 Jun 2011 11:57 AM
no no sry....its showing the correct result but taking too too much time to get a TLE...code it all right....

My program is working

coolmegadeth @ 27 Jun 2011 08:13 PM
My program is working absolutely fine in codeblocks 10.05 (using gnu gcc compiler) ..but on uploading it here..it shows compiler error: /tmp/ccGOEdDH.o: In function `isnotpal': tested.c:(.text+0x7d): undefined reference to `strrev' /tmp/ccGOEdDH.o: In function `main': tested.c:(.text+0x10b): undefined reference to `itoa' collect2: ld returned 1 exit status seems like "strrev" and "itoa" functions are not working on your compiler. What is the problem?

i m getting wrong

sahebrm @ 29 Jun 2011 12:42 PM
i m getting wrong answer..... can please any1 help me with for which case i m getting wrong answer thankx in advance mah code is below import java.io.BufferedReader; import java.io.InputStreamReader; class Main{ public static void main(String[] args) { int n; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { n = Integer.parseInt(br.readLine()); while(true) { n++; if(isp(n)) { if(isprime(n)) { System.out.println(n); break; } } } } catch (Exception e) { System.out.println(e.getMessage()); } } public static boolean isp(int q) { int q1 = q; int q2=0; while(q1>0) { q2 = (q2*10) + (q1 % 10); q1 = q1 /10; } if(q2 == q ) return true; else return false; } public static boolean isprime(int n) { if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; if(n<=8) return true; int fac=5; while(fac*fac<=n){ if(n%fac==0) return false; if(n%(fac+2)==0) return false; fac+=6; } return true; } }

i m getting wrong answer.....

sahebrm @ 29 Jun 2011 12:45 PM
i m getting wrong answer..... can please any1 help me with for which case i m getting wrong answer thankx in advance mah code is below import java.io.BufferedReader; import java.io.InputStreamReader; class Main{ public static void main(String[] args) {int n; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { n = Integer.parseInt(br.readLine()); while(true) { n++; if(isp(n)) { if(isprime(n)) { System.out.println(n); break; } } } } catch (Exception e) { System.out.println(e.getMessage()); } } public static boolean isp(int q) { int q1 = q; int q2=0; while(q1>0) { q2 = (q2*10) + (q1 % 10); q1 = q1 /10; } if(q2 == q ) return true; else return false; } public static boolean isprime(int n) { if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; if(n<=8) return true; int fac=5; while(fac*fac<=n) { if(n%fac==0) return false; if(n%(fac+2)==0) return false; fac+=6; } return true; } }

i m getting wrong answer.....

sahebrm @ 29 Jun 2011 12:47 PM
i m getting wrong answer..... can please any1 help me with for which case i m getting wrong answer thankx in advance the link to mah code is http://www.codechef.com/viewsolution/585316

i tried doing but am getng

coder102 @ 3 Jul 2011 11:36 AM
i tried doing but am getng wrong output.so then realised am assumption abt the given question is wrong... i din understand question properly...ple can anyone tell me the question brfly ??

@admin i m getting wrong

sahebrm @ 3 Jul 2011 08:46 PM
@admin i m getting wrong answer..... can please any1 help me with for which case i m getting wrong answer thankx in advance the link to mah code is http://www.codechef.com/viewsolution/585316

#include #include main() { in

katherine @ 2 Aug 2011 12:17 AM
#include #include main() { int i,n,flag,rnum,j,k; scanf("%d",&n); for(i=n+1;;i++) {k=i; rnum=0; while(k) { rnum=rnum*10+k%10; k=k/10; } if(rnum==i) { flag=sqrt(i); for(j=2;j

plz any1 help me..my code is

katherine @ 2 Aug 2011 12:20 AM
plz any1 help me..my code is giving correct output for evry test case..but its showing runtime error..plzz sm1 help me..m stuck hre http://www.codechef.com/viewsolution/611869

hey all!!! i wanted to share

abhi6691 @ 9 Aug 2011 09:43 AM
hey all!!! i wanted to share my code n see if ny1 cud help me bring down the tym it's taking but every tym i try to post it in a comment it says "comment doesn't support HTML." ny ideas WHY???

@abhi6691 use this

w0rm @ 9 Aug 2011 09:47 AM
@abhi6691 use this http://pastebin.com/

i'm kinda newbie in this, cn

abhi6691 @ 9 Aug 2011 10:03 AM
i'm kinda newbie in this, cn u tell me wat this(pastebin) does???

http://pastebin.com/MtkewU7t

abhi6691 @ 9 Aug 2011 10:09 AM
http://pastebin.com/MtkewU7t ideas ny1 to bring down the time???

@worm thnx man!!!

abhi6691 @ 9 Aug 2011 10:10 AM
@worm thnx man!!!

@katherine add a return 0 at

abhi6691 @ 9 Aug 2011 10:53 AM
@katherine add a return 0 at the end of your code. default return type for main in c is int.

shudn't the output for 99000

ashk @ 10 Aug 2011 04:06 AM
shudn't the output for 99000 be 99099 rather than 1003001 plz reply

srry for above...i forgot the

ashk @ 10 Aug 2011 06:53 PM
srry for above...i forgot the word prime

hey are the single digit no's

coder1 @ 16 Aug 2011 10:37 PM
hey are the single digit no's palindrome. thanks in advance.

my code is running properly

coder1 @ 16 Aug 2011 11:32 PM
my code is running properly on my machine but it is giving wrong answer when i submitted. if any one can find error: import java.util.*; class plndrm { public static void main (String arr[]) { Scanner sc=new Scanner(System.in); int no=sc.nextInt(); int i,j,n,temp,k; int z; if(no==1||no==2) { if(no==2) System.out.println("3"); else System.out.println(no); } else { for( i=no;i<5000;i++) { for(j=2;j

Hi guys..... Most of us

rgaut_89 @ 20 Aug 2011 02:26 AM
Hi guys..... Most of us including me, initially i got the Time Limit Exceed error for this problem.... I don't know about others code but what i found is for any next number first Check weather number is palindrome or not then go for Primality checking. If i reversed the order in my code i got the TLE error. Because Primality checks takes longer time than palindrome test. Hope this information might be useful.

can anyone tell me what is

vprashant3 @ 21 Aug 2011 01:48 AM
can anyone tell me what is wrong with my sol,pls #include int main() { unsigned long int i,j; unsigned long int arr[]={2,3,5,7,11,101,131,151,181,191,313,353,373,383,727,757,787,797,919,929,10301,10501,10601,11311,11411,12421,12721,12821,13331,13831,13931,14341,14741,15451,15551,16061,16361,16561,16661,17471,17971,18181,18481,19391,19891,19991,30103,30203,30403,30703,30803,31013,31513,32323,32423,33533,34543,34843,35053,35153,35353,35753,36263,36563,37273,37573,38083,38183,38783,39293,70207,70507,70607,71317,71917,72227,72727,73037,73237,73637,74047,74747,75557,76367,76667,77377,77477,77977,78487,78787,78887,79397,79697,79997,90709,91019,93139,93239,93739,94049,94349,94649,94849,94949,95959,96269,96469,96769,97379,97579,97879,98389,98689,1003001}; scanf("%ld",&i); for(j=0;;j++) { if(arr[j]>i) { printf("%ldn",arr[j]); break; } } return 0; }

@rgaut_89 : Thanx man u are a

chandank @ 4 Oct 2011 02:13 AM
@rgaut_89 : Thanx man u are a life saver, a simple yet eligent observation great man

Hey admin, my program uses

yudhister @ 14 Oct 2011 05:49 PM
Hey admin, my program uses the predifined list of all prime palindromes ina an array and just checks the smallest value greater than given input. Why am i getting a wrong answer. my list is the same as urs.

@admin: i am getting wrong

potter_nsit @ 28 Nov 2011 10:07 PM
@admin: i am getting wrong answer even though its working in local. Please hellllp: http://www.codechef.com/viewsolution/740256

i hate how ALOT of users are

mohamed_waheed_darko @ 17 Dec 2011 07:16 PM
i hate how ALOT of users are solving the problem by just hard coding the numbers into an array ..... they are not learning anything by doing that , i would like to make a tutorial about this problem and explain a much proper way to solve it , which includes learning new concepts ( which what each problem should do , each problem you solve should teach you something new , and people should pursue solutions with new concepts not take a chance cheating whenever possible ! ) , so if anyone would encourage me to write a tutorial then i will :) , thanks

#include int main() { long

rishabh537 @ 3 Jan 2012 01:24 AM
#include int main() { long int i,n,d,r,count,j; cin>>n; for(i=n;i<=1000000;i++) {r=0;count=0; for(j=2;j<=i/2;j++) if(i%j==0) count++; for(j=i;j>0;j=j/10) {d=j%10; r=r*10+d;} if((r==i)&&count==0) {cout<

i am not understanding that

shivamsharma @ 17 Jan 2012 12:22 AM
i am not understanding that what is problem with my solution can any one help me to check out that errors from which my program is not working.......plzz

have the test cases been

shovikghosh @ 18 Jan 2012 06:18 PM
have the test cases been corrected? i am still getting wrong answer

I tried the sample input in

bunty7_coder @ 22 Apr 2012 01:35 AM
I tried the sample input in my computer as well as some other inputs and they came correct but while submitting here its giving me wrong answer.. can you tell me what input will i test for knowing for sure that its correct..

@Admin..can u pls help me

franky @ 4 May 2012 12:41 PM
@Admin..can u pls help me optimize the solution.. #include #include #include long int a,i; int k,s; int prime(long int); int palin(long int ); int main() { scanf("%ld",&a); for(i=a;;i++) { k=prime(i); if (k==1) { s=palin(i); if (s==1) { printf("%ld",i); break; } } } return 0; } int prime( long int n) {long int j,f,c=0; if(n<=1) return 0; if (n==2) return 1; if (n%2==0) return 0; f=sqrt(n); for(j=3;j<=f;j+=2) { if(n%j==0) return 0; } return 1; } int palin( long int b) { long int x,rem,sum;x=b; while(b>0) { rem=b%10; sum=(sum*10)+rem; b=b/10; } if (sum==x) return 1; else return 0; } its giving ans for all cases ......yet tle....even for boundary casen=1000000

pls look at my

franky @ 4 May 2012 12:43 PM
pls look at my solution... http://www.codechef.com/viewsolution/1011255

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com