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 identified with respect to Base 10 i.e. a regular prime number. Constraints Length of N 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 first 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
Answers
Answer:
. a regular prime number. Constraints Length of N 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 first 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