//A number is called a twisted prime number if it is a prime number
// and reverse of this number is also a prime number.
//Examples: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79
import java.util.*;
class twistedprime
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
int num,i,c=0,temp,r,rev=0,c1=0;
System.out.println("Enter a number:");
num=sc.nextInt();//13
for(i=1;i<=num;i++)
{
if(num%i==0)
c=c+1;
}
if(c==2)
{
temp=num;
while(num>0)
{
r=temp%10;
rev=rev*10+r;//31
temp=temp/10;
}
for(i=1;i<=rev;i++)
{
if(rev%i==0)
c1=c1+1;
}
if(c1==2)
{
System.out.println(num+" is a Twisted Prime Number");
}
else
{
System.out.println(num+" is not a Twisted Prime Number");
}
}
else
{
System.out.println(num+" is not a Twisted Prime Number:");
}
}
}
No comments:
Post a Comment
any problem in any program comment:-