# Doubt in a Question (Prime Face)

Problem Description
Accept a number N up to 5 digits long in the positional numeral system formed by symbols 0, 1, … 9, A, …, Z. Also, accept another symbol S other than zero. Separate N and S with a space. Considering N to be represented in the least base possible between 2 and 36, identify the smallest prime number greater than or equal to N that contains at least one occurrence of S in it in base S + 1. (Refer example section for a better understanding). Prime number should be identiﬁed with respect to Base 10 i.e. a regular prime number.

Constraints

1. Length of N <= 5
2. Max Base = 36
3. Face values for symbols:
Symbol => Value in base 10
0 => 0
1 => 1
2 => 2
….
9 => 9
A => 10
B => 11
….
Z => 35

Input Format
One line containing two integers, N and S separated with space. Output Print the smallest prime number greater than or equal to N that contains at least one occurrence of S in it, in base S + 1.

Output Format
Print the smallest prime number greater than or equal to N that contains at least one occurrence of S in it, in base S + 1.

Example 1
Input
10 B
Output
B
Explanation
The least possible base for N is 2 and its value in that base is 2. We want the smallest prime number in base 12 (1 more than the face value of B, 11) that contains symbol B and is greater than or equal to 2. The ﬁrst few numbers in ascending order in base 12 containing face value B are B (value 11), 1B (value 1 * 12 + 11 = 23), 2B (value 2 * 12 + 11 = 35): of these the smallest number that is prime is 11, which is greater than N. Hence, the output is B.

Example 2
Input
ZZ Z
Output
11Z
Explanation
The least possible base for N is 36 and its value in that base is 35 * 36 ^1 + 35 = 1295. The ﬁrst few numbers in ascending order in base 36 (1 more than the face value of Z, 35) containing face value Z and greater than N are 10Z (1 * 36^2 + 0*36^1 + 35 = 1331, non-prime), 11Z (1 * 36^2 + 1 * 36^1 + 35 = 1367, a prime). Hence, the output is 11Z.

The problem occured in Codevita, Simple enough but It gave WA, been thinking about it since then still I am not able to find the mistake I made.

My approach

```tot="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
N,S=input().split()
bas=tot.find(max(N))+1
mini=int(N,bas)
Splus=tot.find(S)+1

while True:
if isPrime(mini)==True and S in toBase(mini,Splus):
print(toBase(mini,Splus))
break
mini+=1```

Is it from ongoing ??

No, it’s from CodeVita zone 2

1 Like

Tcs codevita ( vhi pagalpanti) …

1 Like

Off Course not…The contest finished a day ago.

Whats wrong with asking doubts after the contest?

No problem …u proceed