I think there is some glitch in this problem. I’ve submitted all the possible answers. I think my solution is correct but this is showing incorrect everytime
IMG_20211212_170509|660x500
I was also confused at first to solve this question.
In this community, I created a topic about it.
Here is it → A confusion in the problem
Doesn’t work though
Here is .cpp code for you that will let you know all the combinations that can be possible and total such numbers :
#include <bits/stdc++.h>
using namespace std;
int p[10000];
int oneDigit(int num)
{
return (num >= 0 && num < 10);
}
bool isPalUtil(int num, int* dupNum)
{
if (oneDigit(num))
return (num == (*dupNum) % 10);
if (!isPalUtil(num / 10, dupNum))
return false;
*dupNum /= 10;
return (num % 10 == (*dupNum) % 10);
}
int isPal(int num)
{
if (num < 0)
num = -num;
int* dupNum = new int(num);
return isPalUtil(num, dupNum);
}
int main()
{
int size=0;
int count=0;
int k=0;
for(int i=1000;i<10000;i++)
{
if(isPal(i)) p[size++]=i;
}
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if(p[i]-p[j]>1000){
if(isPal(p[i]-p[j])) { k=1; cout<<“Pi=”<<p[i]<<" Pj=“<<p[j]<<” deff="<<p[i]-p[j]<<endl; }
}
if(k==1) { count++ ; k=0; }
}
}
cout<<“Total such palindromes =”<<count;
}
OUTPUT :
Ans will be above 1970.