You are on page 1of 5

Lost Primes

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
Date: 20091215 Time limit: 4s Source limit: 50000 Languages: C C99 strict C++ 4.0.08 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK TEXT JS

#include<iostream.h> #include<conio.h> #include<math.h>

#include<time.h> long int ascii(long int a2) { switch(a2) { case 48: return 0; case 49: return 1; case 50: return 2; case 51: return 3; case 52: return 4; case 53: return 5; case 54: return 6; case 55: return 7; case 56: return 8; case 57: return 9; } }

long int check(long int a1) {

for(int i=2;i<=sqrt(a1);i++) { if(a1%i == 0) {goto c;} }

return 1; c: ; }

void main() { char a[14]; long int i=0,len=0,j,k[14],b[14],noi=0,j1; long int i1=0,count,m,n; clock_t start, end; long double r1=0; cin.getline(a,14); start = clock(); while(a[i] !='\0') { len=len+1; if(a[i]!='*') { n=(int)a[i]; b[noi]=ascii(n); k[noi]=i; noi=noi+1;

} i=i+1;

for(j=pow(10,(len-1));j<=pow(10,len);j++) { count=0; int temp=check(j); if(temp==1) { for(m=0;m<=(noi-1);m++) { j1=j;

int r,g; for( g=1;g<=(len-k[m]);g++) { r=j1%10; j1=j1/10; }

if(r==b[m]) { count=count+1; if(count==noi){cout<<j<<"\n";goto s; } else;

} else ; }

} } s:; end=clock(); cout<<"\nThe time was: \n"<<((end - start) / CLK_TCK); r1=r1+(double)((end - start) / CLK_TCK); cout<<"\nTotal time = "<<r1; getch(); }

You might also like