Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
3.0 kB
1
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstring>
int middle1 = 1, middle2;
int check1, coprime;
int check2 = 0;
void coPrime(int num1, int num2)
{
	 int hcf, i;
	 for(i=1;i<=num1;i++)
	 {
	  if(num1%i==0 && num2%i==0)
	  {
	   hcf = i;
	  }
	 }
    coprime = 0;
	 // Making Decision
	 if(hcf == 1)
	 {
	  coprime = 1;
      }
	 
}

void Digitcheck(int N)
{
    // To store the digit
    // of the number N
    int arr[100];
    int p = 0;
    int j, r;
    check1 = 1;
    // Till N becomes 0
    while (N != 0) {
  
        // Extract the last digit of N
        r = N % 10;
  
        // Put the digit in arr[]
        arr[p] = r;
        p++;
  
        // Update N to N/10 to extract
        // next last digit
        N = N / 10;
    }
  
    // Print the digit of N by traversing
    // arr[] reverse
    for (j = p - 1; j > -1; j--) {
        int first,second;
        
        if (j != 0){   
            first =(arr[j] - arr[j - 1]);
            if (first < 0) {
                first = first * (-1);
            }
        if(  (first!=1))
        {  
          if (1)  
            {
                check1 = 0;
            
            }
    }
}
}
}
bool isPalindrome(int number)
{
    // 3
    string str_number = to_string(number);

    // 4
    int j = strlen(str_number.c_str()) - 1;
    
    // 5
    for (int i = 0; i < j; i++, j--)
    {
        if (str_number[i] != str_number[j])
        {
            // 6
            return false;
        }
    }

    return true;
}

int main()
{
    // 1
    for(int i =100; i<= 1000000000; i++){
        // 2
        if(isPalindrome(i)){

            
            int count = 0;
            int app;
            app=i;
            while (app!= 0)
            {
                app = app / 10;
                count = count + 1;
            }

            
            if (count%2!=0 )
            {       
                    Digitcheck(i);
                   
                    if (check1 == 1){   
                            int digits = (int)log10(i) + 1;

                            
                                middle2 = (int)(i / pow(10, digits / 2)) % 10;
                                coPrime (middle1,middle2);
                                if ( coprime == 1)
                                {
                                    
                                      check2 = check2 +1;
                                      if (check2 == 56)
                                      {   
                                      
                                            cout << i <<endl;
                                      }
                                        
                                
                                }
                                middle1=middle2;
                            
            }
        
        }
    }
}
    return 0;
    
}