Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

wrong answer in prime pallindrome .please tell problem?

$
0
0

When I ran this code int turbo c++ the answer to 31 was coming correctly to be 101.But when I submitted it was giving that "wrong answer"!Please tell me problem?

include<stdio.h>

long int pal(long int l) { long int rev=0,rem; long int x=l; while(x!=0) { rem=x%10; x=x/10; rev=(rev*10)+rem; } if(rev==l) return(1); else return(0); }

long int prime(long int b) { long int c=0; for(long int i=1;i<=b;i++) { if(b%i==0) c++; } if(c==2) return(1); else return(0); }

main() { long int n,m,k=0; scanf("%d",&n); for(long int i=n+1;i<=1000000;i++) { if(pal(i)) { if(prime(i)) k=1; } if(k==1) {m=i; break;}

} printf("%d",m); }


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>