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 » Compete » January 2010 (Contest XII) » Lost Primes

Lost Primes

Problem code: L3

  • 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:
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.

for above test cases:---- the

unpredictable0 @ 1 Jan 2010 03:33 PM

for above test cases:----

the answers

2

13

101

 

will be correct or not??????????

Read the second sentence

triplem @ 1 Jan 2010 03:34 PM

Read the second sentence after 'Output'.

you can print any of them..

mcsharma1990 @ 1 Jan 2010 03:41 PM

you can print any of them..

what can be maximim numbrer

anurag_aggarwal @ 1 Jan 2010 04:53 PM

what can be maximim numbrer of missing digits

any idea

may be all are missing...in

mcsharma1990 @ 1 Jan 2010 05:18 PM

may be all are missing...in that case you have to print any prime containig those may digits..

is long long allowed in c

stonecold @ 1 Jan 2010 07:50 PM

is long long allowed in c programming?

Yes

mcsharma1990 @ 1 Jan 2010 08:55 PM

Yes

are we allowed to precompute

anirudhsaraf @ 2 Jan 2010 01:35 AM

are we allowed to precompute things and read from a file ?

 

Thanks,

Ani

can any one help me with i/o

congizance @ 2 Jan 2010 02:14 AM

can any one help me with i/o stream in java... Can we use BufferedReader??

File access is not

triplem @ 2 Jan 2010 02:21 AM

File access is not allowed.

@amit click on Discuss - Wiki at the top of the page.

For some reason, they are

tarifezaz @ 2 Jan 2010 01:34 PM

For some reason, they are showing the message "problem_id_required" just when I'm trying to submit this problem. The main page is showing that I have been getting TLE, but I keep on getting the same old "problem_id_required" message. What's going wrong? I tried both the button, the one on the right and the one at the bottom left. I submitted in CodeChef before, but this is the first I have been facing this problem. Can anybody help? As far as I know, there should be a small box showing the judge verdict after submitting a problem. Am I missing something new?

tarif

Oh! Finally the invisible

tarifezaz @ 2 Jan 2010 01:37 PM

Oh! Finally the invisible "problem_id" appeared! thanks :D

for above test case can the

princeseth2006 @ 3 Jan 2010 01:04 PM

for above test case

can the answer be

7

43

103

 

@prince yes

rampage @ 3 Jan 2010 02:28 PM

@prince

yes

can you please check if my

sandeepkkothari @ 3 Jan 2010 07:23 PM

can you please check if my code is wrong or not  as the compiler for php seems to have some problem... for every test inputs it gives me correct answer but your compiler says it as wrong answer ! .. kindly confirm !

Not relating to the above

udaydeep_1990 @ 3 Jan 2010 10:04 PM

Not relating to the above question, but a general question : What does the Accuracy ( the stat on the rightmost column of every problem ) mean ?

i get always wrong

mukulrajput @ 3 Jan 2010 10:17 PM

i get always wrong answer....but i cn't understand where i m worng....plzzzzz someone help...

dat is my code where i m worng plz tell me..

#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
int main()
{
int a[14];
char s[14];
int b,c,i,k;

while(scanf("%s",s)!=EOF){
k=strlen(s);

c=0;
for(i=0;i<k;i++)

{

if((s[i]=='?')&&i!=k-1)
a[i]=abs(i-1);

else if((s[i]=='?')&&(k==2)&&(s[i-1]!='3'))
{

if(c%3==0)    
a[i]=7;

else
a[i]=3;
}
else if(s[i]=='?')
{
c=c+7;
if(c%7==0)
a[i]=1;
else if(c%3==0)
a[i]=3;
else
a[i]=7;

}
else
{
c=c+s[i]-'0';
a[i]=s[i]-'0';
}
}
for(i=0;i<k;i++)
printf("%d",a[i]);
printf("n");
}
return 0;
}           

@Uday: Accuracy is

pieguy @ 4 Jan 2010 01:06 AM

@Uday: Accuracy is 100*(number of correct submissions)/(total number of submissions).  It's value roughly reflects the difficulty of a problem, but sometimes (especially with the tiebreaker problem) is skewed by people who make multiple correct submissions.

@mukul: posting code is not allowed during the contest.  Nor is posting hints.

I submitted solution in java.

pda @ 4 Jan 2010 01:27 AM

I submitted solution in java. Its consuming 220MB memory.I am getting Error(OTHER).

Whats the memory limit for running this progra?

Thanks

plz someone help me....give

mukulrajput @ 4 Jan 2010 03:16 AM

plz someone help me....give me some test case .........

thankxxxxxx

No, nobody can do that.

triplem @ 4 Jan 2010 03:34 AM

No, nobody can do that.

Hi,  am trying to use long

sharma.illusion @ 4 Jan 2010 01:26 PM
Hi,  am trying to use long long in g++ 4.0.0 but everytime I get the following compilation error. I try to initialize variable using following
long long var = 999999999999; (12 digits in total)
/sources/tested.cpp:44: error: integer constant is too large for 'long' type /sources/tested.cpp:136:2: warning: no newline at end of file /sources/tested.cpp: In function 'long long int findPrimes(char*, int)': /sources/tested.cpp:73: warning: converting to 'long long int' from 'double'

use: long long var =

havaliza @ 4 Jan 2010 01:41 PM

use:

long long var = 999999999999LL;

Please don't give away hints

admin @ 4 Jan 2010 03:53 PM

Please don't give away hints related to contest problems.

Will the test case contain a

ds.sundar @ 4 Jan 2010 05:40 PM

Will the test case contain a prime number with out the ? mark... In this case the app need to print the number as it is...

Will the ? appear only in front and end or any where in the number?

it is my worst experience on

gurpreet_09 @ 4 Jan 2010 08:59 PM

it is my worst experience on codechef ...

this time for taking any input (pattern) i used #include<string> and string data type..........

and i got TLE about 15 times :( :(

but when i changed and used shar datatype 4 inputing pattern it took only  0.41 sec ................

Plz xplain why it happened.........

from TLE(>4sec) to 0.41 sec is big difference it means we must use char data type rather than string??????????????????????

plz help

it is my worst experience on

gurpreet_09 @ 4 Jan 2010 09:01 PM

it is my worst experience on codechef ...

this time for taking any input (pattern) i used #include<string> and string data type..........

and i got TLE about 15 times :( :(

but when i changed and used *char datatype for inputing pattern it took only  0.41 sec and got AC................

Plz xplain why it happened.........

from TLE(>4sec) to 0.41 sec is big difference it means we must use char data type rather than string??????????????????????

plz help

I don't think that this is

admin @ 4 Jan 2010 09:20 PM

I don't think that this is the case. I took your code which ran in 0.41 seconds and changed it to accept input using strings and it got accepted. Your code might have timed out because of other inefficiences.

Will the test case contain a

ds.sundar @ 5 Jan 2010 12:30 PM

Will the test case contain a prime number with out the '?' mark... In this case the app need to print the number as it is...

Will the '?' appear only in front and end or any where in the number?

@Sundaram Have you read the

triplem @ 5 Jan 2010 03:37 PM

@Sundaram Have you read the third sentence of the problem statement?

If ? could only occur at the start or end, it would say ? can only occur at the start or end. It doesn't.

thnx for quick reply :). as u

gurpreet_09 @ 5 Jan 2010 04:13 PM

thnx for quick reply :).

as u said aniruddha i tried again with string data type and got TLE :(

submission id is 159816 and 159817(tried 2 times)

i hv compiled my code in

jackofcyber @ 5 Jan 2010 08:29 PM

i hv compiled my code in turbo c n it runs fine!!without error n warnings.

i hv uploaded d file here n it gives following compilation error

/tmp/ccT20vDe.o: In function `main': tested.c:(.text+0x13): undefined reference to `clrscr' tested.c:(.text+0x405): undefined reference to `strrev' tested.c:(.text+0x45f): undefined reference to `getch' tested.c:(.text+0x51b): undefined reference to `strrev' collect2: ld returned 1 exit status

anyone plz help fast!!

Don't use turbo C. Read

admin @ 5 Jan 2010 08:50 PM

Don't use turbo C. Read www.codechef.com/wiki

i ma used 2 turbo c i hvnt

jackofcyber @ 5 Jan 2010 09:11 PM

i ma used 2 turbo c

i hvnt used any other compliler evn 1nce!!

plz tell me hw 2 write code in dev cpp(i hv dwloaded)

is der any difference in code btwn turbo c and dev c!!

if yes what r dey?

Read the wiki.

admin @ 5 Jan 2010 09:22 PM

Read the wiki.

Hi Admin,   I have submitted

ds.sundar @ 5 Jan 2010 09:29 PM

Hi Admin,

 

I have submitted my code three time and all the three times it says wrong answer. However the code working fine in my system. Can you tell me to which test case my code fails....  will a newline at the end or in the begining also matters in the output? Please help me....

 

Thanks & Regards

Sundaram. D

Newline at the end won't

admin @ 5 Jan 2010 10:00 PM

Newline at the end won't matter. The code is tested against test cases other than the ones mentioned in the problem statement. The data with which you are testing your code might not be as exhaustive.

i m getting tle error in my

jackofcyber @ 6 Jan 2010 02:49 PM

i m getting tle error in my program!!

in every time i make some change i hv 2 upload and check if it sits into the given time.

is der any way to find out the time into dev's compiler? or ur computer without uploading to dis dite!!

The system specs are

triplem @ 6 Jan 2010 03:18 PM

The system specs are mentioned in the wiki. You could try setting up your computer in the same way.

Speaking english so people could understand you might help too ;)

I hav submitted my code in

pankajnsit @ 6 Jan 2010 03:36 PM

I hav submitted my code in C..But I gt a 'wrong answer' error...

The code seems to be working fyn on my system and I hav also tried various test cases...Can I plz know the test case for which my code

failed..

Nope, not until after the

triplem @ 6 Jan 2010 03:52 PM

Nope, not until after the contest.

  The time limit of 4 s is

late_nighter @ 6 Jan 2010 04:42 PM

 

The time limit of 4 s is for one test case or for multiple test cases. I am assuming one test case = 1 input file with t number of inputs. So 4s , is it for one input file or multiple input files ?

One set of inputs = Number of

admin @ 6 Jan 2010 04:56 PM

One set of inputs = Number of test cases followed by those many test cases. The time limit for all this is 4 seconds.

Do the known digits can be

alok @ 6 Jan 2010 07:58 PM

Do the known digits can be more than one?

Please be more specific.

admin @ 6 Jan 2010 08:05 PM

Please be more specific.

i m not getting the result

Rakaesh @ 6 Jan 2010 08:13 PM

i m not getting the result for my submission.

plz somebody help me!!

the process keeps on running.

Rakaesh @ 6 Jan 2010 08:17 PM

the process keeps on running.

Hi, I submitted my solution

rishabhgupta @ 7 Jan 2010 12:10 AM

Hi,

I submitted my solution and getting a runtime error.Where can i exactly see wht type of run time error is it.Cause its working fine in my desktop.

Like can this be the input : 

alok @ 7 Jan 2010 05:05 AM

Like can this be the input :  ??3??1?

Like can this be the input : 

alok @ 7 Jan 2010 05:06 AM

Like can this be the input :  ??3??1?

Of course.

triplem @ 7 Jan 2010 05:38 AM

Of course.

hi Aniruddha my code is

nikhilele @ 7 Jan 2010 04:23 PM

hi Aniruddha

my code is working but codechef is saying wrong ans...

can u throw some light


to the Admin for the below

parth_gupta @ 7 Jan 2010 04:25 PM

to the Admin

for the below input

521??25?11???3?7?5    my program is giviing output like
521312521103031725

 

is the answer correct?

if yes then

i guess in all the circumstances my answer is giving right output then why judje is givin me wrong answer.. Admin please assist.

@nikhil and Parth No, the

triplem @ 7 Jan 2010 04:26 PM

@nikhil and Parth

No, the admin cannot help you. This is a contest problem.

@Parth Gupta Your input is

cena @ 8 Jan 2010 05:11 PM

@Parth Gupta

Your input is wrong as there is no prime ( Except 5 ) that ends with 5 :)

It will be great if there are

manu_123 @ 8 Jan 2010 11:00 PM

It will be great if there are some more sample input and ouput sets.

why these  answers are wrong. for the sample input

Input:
3
?
?3
1??

Output

 

2

13

101

please clarify

Thanks in advance !!

 

Who said they are wrong? The

triplem @ 9 Jan 2010 02:10 AM

Who said they are wrong? The problem clearly says there can be multiple correct answers.

any hints for reducing time

sai4anand @ 9 Jan 2010 06:15 PM

any hints for reducing time limit??

You will not be given hints,

triplem @ 10 Jan 2010 02:44 AM

You will not be given hints, no.

Hi, on my laptop I am getting

mtk @ 11 Jan 2010 02:15 PM

Hi,

on my laptop I am getting correct answer for the 100's of examples I tried for at most 12 digits.But while submitting it says wrong answer.May I know what kind of input lead my program give wrong answer.

 

Thanks.

No, you may not :)

triplem @ 11 Jan 2010 02:28 PM

No, you may not :)

Hi, I have 3 doubts 1] for

mtk @ 11 Jan 2010 07:55 PM

Hi, I have 3 doubts

1] for input : ???0???

is the output : 1000003 correct ?

 

2] Do we have to specify "Output"  <without the quote> in the answer?

 

3] can the hidden number in any test case be other than prime ? i.e. do we have to handle such cases? If yes then what to output for such case?

1) Of course it is.. why

triplem @ 12 Jan 2010 08:03 AM

1) Of course it is.. why wouldn't it be?

2) No. Just the solutions.

3) Read the last line of the output section.

Getting 'Wrong answer',

Shoonya @ 14 Jan 2010 10:04 PM

Getting 'Wrong answer', though i checked all cases, i can think of.

Any hint about corner cases ?

Wait until after the contest

triplem @ 15 Jan 2010 02:09 AM

Wait until after the contest has finished.

hmmmm shouldnt there be

foofoo @ 15 Jan 2010 02:44 PM

hmmmm shouldnt there be approval for comments from the admin ?? ...what if i post my code here ..as in any case i am not gonna win .. :P

Then you would probably be

triplem @ 15 Jan 2010 02:46 PM

Then you would probably be disqualified from all future contests :)

hehehe

foofoo @ 15 Jan 2010 02:50 PM

chickening outhehehe

Now, as the contest is over,

jyotesh @ 15 Jan 2010 03:05 PM

Now, as the contest is over, I think someone can help me.

I am getting runtime error (SIGSEGV). Can the admin please let me know why I am getting this error?

My submission ID is 162741.

where can we get the

codechef_latest @ 15 Jan 2010 08:08 PM

where can we get the solutions..

search for solutions in this

sppraveen @ 15 Jan 2010 08:13 PM

search for solutions in this page.

@Jyotesh - your program has a

triplem @ 16 Jan 2010 04:26 AM

@Jyotesh - your program has a few bugs in it. Try this as input:

2
???????????7
???????????7

The first case your program prints out a number ending with 3; the second case it crashes.

@Admin, I also got 'Wrong

Shoonya @ 16 Jan 2010 10:02 PM

@Admin,

I also got 'Wrong answer' for this problem.

Can you please tell, for which case my solution failed.

For above input,

my output is

 

2

100000000019

100000000019

Submission ID: 168260

Shoonya @ 16 Jan 2010 10:07 PM

Submission ID: 168260

@Admin I was looking for

Shoonya @ 16 Jan 2010 10:25 PM

@Admin

I was looking for correct solution for this problem.

Found this ID: 165066

Copied the code and tried few test cases...

strange but it's not giving answer if i am giving "11??12??" as input, working fine for inputs like "????????"

...

Don't know how it's accepted...

No response after 2 days :(

Shoonya @ 18 Jan 2010 09:26 PM

No response after 2 days :(

Mohit, it's "about 15 test

MichaelD @ 18 Jan 2010 11:58 PM

Mohit, it's "about 15 test cases", not "at most".

One reason might be because

prodigyaj @ 19 Jan 2010 06:47 AM

One reason might be because the code uses printf("%lld") to print the long long value. printf for long long usually gives incorrect output on my dev-cpp compiler but works correct on the codechef server. You can try modifiying printf to cout which should give u the right answers !!

@Michae, Ajay   Thanks for

Shoonya @ 20 Jan 2010 09:25 PM

@Michae, Ajay

 

Thanks for response.

Is there any way, i can check my solution, after challenge is over for this problem ?

I don't see 'Submit' button on top of this page.

 

All problems are moved to the

MichaelD @ 20 Jan 2010 11:14 PM

All problems are moved to the practice area after a contest. Go <a href="http://www.codechef.com/problems/L3/">here</a>.

Whoops. That didn't work too

MichaelD @ 20 Jan 2010 11:20 PM

Whoops. That didn't work too well, but you got the address there.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
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