PROBLEM LINK
Setter- pavan sai kiran
Editorial - pavan sai kiran
DIFFICULTY:
Easy
PREREQUISITES
Palindrome,radix number system
PROBLEM
You will be given a number ‘n’ and a radix base ‘b’ and now you have to convert that number into its corresponding in the base ‘b’ and check whether it is a palindrome or not.
Explanation
what you have to do is just run a while loop and keep on dividing the given number ‘n’ with base ‘b’
till the number ‘n’ becomes 0 and store all the remainders in an array.
Now if we combine the numbers in that array from right to left and form a new number , now this number is the actual number that ‘n’ in radix base ‘b’.
Now you just have to check whether this number is a palindrome or not and for this you just need to check whether ith element in the array is equal to l-i-1th element in the array where l is the length of the array for all i=0,1,2,3…,l/2.
for example n=16 and b=3 now the array will be [1,2,1]
here l=3 and i=0,1
the statement ith element in the array is equal to l-i-1th element is satisfied.
Therefore, this is a palindrome and thus “YES” must be printed.
Solution
Setter’s solution can be found here.