Twisted Prime

The program must accept an integer N as the input. The program must print YES if N is a twisted prime number. Else the program must print NO as the output. A number is said to be twisted prime if it is a prime number and reverse of the number is also a prime number.
Boundary Condition(s):
1 <= N <= 10^16
Input Format:
The first line contains the value of N.
Output Format:
The first line contains either YES or NO.
Example Input/Output 1:
Input:
97
Output:
YES
Explanation:
97 is a prime number.
The reverse of 97 is 79. So 79 is also a prime number.
Hence the output is YES
Example Input/Output 2:
Input:
34
Output:
NO

Solution :-

#include<stdio.h>
#include <stdlib.h>

int isprime(int  n)
{
    for(int i=2;i<=n/2;i++)
    {
        if(n%i==0)
        return 0;
    }
    
    return 1;
}

int main()
{
    int n;
    int x=0,y=0;
    int f1=0,f2=0;
    scanf("%d",&n);
    x=n;
    
    while(x!=0)
    {
        y=y*10+x%10;
        x=x/10;
    }
    
    
    f1=isprime(n);
    f2=isprime(y);
    
    
    if(f1==1 && f2==1)
    printf("YES");
    else
    printf("NO");
    
   
    


}

Comments

Popular posts from this blog

Two Matrix Spiral Print

Alphabets Positions Reversed

Odd Factors - (Error Identification) skillrack program id - 7306