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) » Lost Primes

Lost Primes

Problem code: L3

  • Submit
  • All Submissions

All submissions for this problem are available.

The BSA (Bytelandian Security Agency) has intercepted several secret keys from the Trojan Kingdom. Each secret key is a prime number. But BSA was only able to retrieve some part of the digits, not all of them!

Johnny's job is to help BSA recover these lost primes, and he has delegated the task to you!

Input

The first line contains a number t (about 15) which is the number of test cases. Then t test cases follow. Each test case is described in a single line containing the patterns of the lost primes (the unknown digits are represented by '?'s.

Each pattern's length is at most 12.

Output

For each test case, print the recovered prime. If there are multiple solutions, print any of them. The recovered prime should have the same number of digits as the corresponding pattern and should contain no leading zeros.

You can assume that there is at least one solution for each test case.

Example

Input:
3
?
?3
1??

Output:
5
23
101

Author: duc_admin
Date Added: 15-12-2009
Time Limit: 4 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, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, 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.

plz help me.. i hav tried

pankajnsit @ 16 Jan 2010 12:40 AM

plz help me..

i hav tried submitting this prob many times but it always says "Wrong answer"..

admin can u plz tell me the test case for which it is giving the wrong answer as I have tested various test cases succcessfully on my system..

I am getting run-time

jyotesh @ 16 Jan 2010 11:32 AM

I am getting run-time error(SIGSEGV). Can someone tell me why I am getting this error?

My submission ID is 169225.

@Pankaj: usually the

jcomeau_ictx @ 19 Jan 2010 12:51 PM

@Pankaj: usually the testcases are posted after a contest, but this time they weren't (or if they were, I can't see where). Just a suggestion: have you tried a testcase of "?" And at least one testcase of length 12? And some testcases with no question marks at all?

@john:thanx for the

pankajnsit @ 20 Jan 2010 04:23 AM

@john:thanx for the suggestion but I hav already tried all of des test cases and am gettng the desired output..

dunno wats d mistake..admin plz help..

char

triplem @ 20 Jan 2010 06:19 AM

char s[12];
..
scanf("%s",s);

That definitely won't work on a string of length 12.

I'm compelled to write to you

kingmansoor @ 20 Jan 2010 06:49 PM

I'm compelled to write to you as I'm really curious to know what is expected out of programmers in this problem. It is quite clearly mentioned that any of the prime numbers can be taken if there are multiple prime numbers of the same digits. I've tried and tested my program several times and got it correct. Even now I'm getting "WRONG ANSWER" when I submit my solution. Kindly clarify the problem.

Plz help

kingmansoor @ 20 Jan 2010 06:53 PM

Plz help

Kindly clarify the question

kingmansoor @ 20 Jan 2010 06:56 PM

Kindly clarify the question or modify the test engine to accept the correct answer. As per what is asked I'm getting the correct output but the compiler is rejecting it every time I submit my solution. Plz throw some light on this problem.

@king: at least 147 unique

jcomeau_ictx @ 21 Jan 2010 12:14 AM

@king: at least 147 unique solutions, accepted as correct by the judge, have been posted between this page and the corresponding page under the January competition, all of which are viewable. why not pick one in your preferred language and read it? or at least tell us what needs to be clarified.

Codechef is rejecting your

triplem @ 21 Jan 2010 02:18 AM

Codechef is rejecting your solution because it is very plainly incorrect for a huge number of reasons. Please read the FAQ before making another comment.

(You say you tested your code, but that seems very unlikely as it giving the wrong results for virtually all test cases I can think of.)

@John My situation is also

Shoonya @ 21 Jan 2010 10:07 PM

@John

My situation is also similar to Pankaj.

Tried with all test cases i can think of (ofcourse including 12'?')

One doubt..

If input is pattern don't have any '?' and not a prime, then what should be output ?

say '1222'

 

Right now i am printing same pattern for them. '1222'

 

Is this correct ?

 

Shoonya !!

@stephen:got my

pankajnsit @ 22 Jan 2010 12:45 AM

@stephen:got my mistake...

thanx a lot...

@Mohit: what you're doing is

jcomeau_ictx @ 22 Jan 2010 03:36 AM

@Mohit: what you're doing is correct, but there are no such nonprime constants in the list, apparently.

if you're using optimized input routines, watch out for DOS-type endlines of rn rather than just n. not sure this is one of those, but there are a few problems with input files like that.

@ Mohit Tried with all test

triplem @ 22 Jan 2010 06:05 AM

@ Mohit

Tried with all test cases you could think of? It seems to fail on most of them. For example, ?3; you print out 17.

Hi, I have been trying my

sunilbhatia79 @ 26 Jan 2010 12:18 PM

Hi,

I have been trying my solution for a lot of times now... I always get a Runtime Error. Could it be because of the memory... although I may be wrong... but I think that the code seems to be working well with all the test cases that I could think of... also I have not faced any Runtime Exception yet.

Regards.

Sunil

One reason that you will

triplem @ 26 Jan 2010 12:38 PM

One reason that you will definitely get a runtime exception with that code is mentioned in the FAQ.

@Stephen: thank you for your

sunilbhatia79 @ 27 Jan 2010 12:54 PM

@Stephen: thank you for your comment. The issue was with memory and also I did not return the main() with "return 0". I guess I should be reading the FAQ more carefully :). Thank you again.

My submission id is 702373.

sai16vicky @ 14 Oct 2011 06:27 PM
My submission id is 702373. Why am getting WA? I have tested with the extreme cases also. Please help!!!!!

what is the maximum limit

flingo_1992 @ 18 Feb 2012 07:34 PM
what is the maximum limit upto which we should check for

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