Click here to read the complete problem statement.
Please give me a hint. I tried it many times. But I can’t solve it.
How can it possible?
Use brute force. C++ or python
def palindrome(n):
temp = n
rem=0
rev=0
while(temp!=0):
rem = temp%10
rev = rev*10+rem
temp = int(temp / 10)
if(rev==n):
return True
else:
return False
def check_prime(n):
count = 0
for i in range(2,n):
if n % i == 0:
count = count + 1
if count==0 and n!=1:
return True
else:
return False
num = 7117
pal = 0
n=1
while True:
print(n)
if check_prime(n):
pal = num + n
if palindrome(pal):
print(pal)
break
pal = 0
n = n + 1
Its not that difficult. Here are some observations to help-
The palindrome number we’ll get after adding the prime number cannot be a four digit palindrome, as all the numbers added to 7117 to make a four digit palindrome are divisible by 11.
We know that, all prime numbers except for 2 can only have 1,3,7 and 9 as their units place number.
Let assume, the palindrome we will get is 5 digit minimum.
By adding 1 to 7117’s unit place number 7, we get that, the palindrome will be 8aba8.
If added 3, we get 0aba0 not possible.
If added 7, we get 4aba4.
If added 9, we get 6aba6.
Out if all this, the smallest number would be 4aba4. Then, the units place of the prime number would be
4. Now, the 5th place digit of the prime has to be minimum 3, or else it will be impossible to 4aba4.
There are many more observations to solve this question, i’ll leave the rest to you as it isn’t too difficult anymore. Hope this helped.
@Aquamarine1210 thanks a lot ! I followed your suggestion, and got the correct answer.