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

×

PRPALIN - Editorial

PROBLEM LINK:

Practice

Author: ADMIN

Editorialist: SUSHANT AGARWAL

DIFFICULTY:

SIMPLE

PREREQUISITES:

Basic looping,Conditional statements

PROBLEM:

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.

EXPLANATION:

Check every odd number after N (using a loop) for 2 properties

1)It should be prime 2) The number should be equal to its reverse.

Print the first number that satisfies these 2 properties and then break out of the loop when this number is encountered.

EDITORIALIST'S SOLUTION:

Editorialist's solution can be found here.

This question is marked "community wiki".

asked 18 Dec '14, 16:56

sushant96's gravatar image

0★sushant96
21368
accept rate: 0%

edited 02 Jan '15, 17:25

admin's gravatar image

0★admin ♦♦
19.8k350498541

1

Nice job, but please format your code if you want someone to be able to understand it easily - use for example this - http://prettyprinter.de/index.php

...after N...

is not correct, M >= N right?

(18 Dec '14, 17:45) betlista ♦♦3★

include<stdio.h>

include<math.h>

int check(int num) { int rev_num = 0; while(num > 0) { rev_num = rev_num*10 + num%10; num = num/10; } return rev_num; } int main() { int n,i; scanf("%d",&n); if(n==1) { printf("2\n"); } else if(n==2) printf("3\n"); else{ if(n%2==0) n++; else n=n+2; do{ int x=sqrt(n); for(i=3;i<=x;i++) { if(n%i==0) break; } if(n%i!=0) { int j=check(n); if(j==n) { printf("%d\n",n); break; } } n=n+2; }while(1); } return 0; } why this not work

link

answered 14 Feb '15, 13:05

grb47's gravatar image

4★grb47
1
accept rate: 0%

Please ask questions in Discuss -> Forums -> Ask a Question.

Do not post questions like this as an answer.

(14 Feb '15, 13:33) arun_as1★

The solution given in this editorial is wrong. For the input of 10010 it gives output 10201 but rather it should be 10301

link

answered 21 Feb '15, 07:13

lincoln's gravatar image

1★lincoln
1
accept rate: 0%

answer is right..10201 is smaller than 10301

link

answered 17 Apr '15, 01:07

shashaa35's gravatar image

4★shashaa35
25114
accept rate: 0%

why my solution is going for tle,.. http://www.codechef.com/viewsolution/6782096

link

answered 17 Apr '15, 01:17

shashaa35's gravatar image

4★shashaa35
25114
accept rate: 0%

10201 is divisible by 101 hence it is not a prime no Hence the awnser for 10010 is 10301

link

answered 25 Sep '15, 22:14

george1996's gravatar image

2★george1996
1
accept rate: 0%

10201 is divisible by 101 hence it is not a prime no Hence the answer for 10010 is 10301

link

answered 25 Sep '15, 22:14

george1996's gravatar image

2★george1996
1
accept rate: 0%

sir i have applied seive of atkins to found prime but still getting tle

link

answered 20 Feb '16, 22:20

shobhit99924's gravatar image

4★shobhit99924
16
accept rate: 33%

have u submitted it or checking it in codechef IDE?

link

answered 20 Feb '16, 22:37

babai_108's gravatar image

3★babai_108
112
accept rate: 0%

Serious issue - Editorialist's solution is wrong as output for 10000 is 10201 which is 101^2. This also means that the testcases are weak.

link

answered 21 Jan, 19:26

satyankar_2005's gravatar image

2★satyankar_2005
91
accept rate: 0%

edited 21 Jan, 19:28

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:

×15,852
×3,820
×191
×43

question asked: 18 Dec '14, 16:56

question was seen: 5,956 times

last updated: 21 Jan, 19:28