OR
Write a program in java to enter a number and check whether the number is emirp number or not .
An Emirp number is a number which is prime backwards and forwards.
Example: 13 and 31 are both prime numbers.Thus, 13 is an emirp number.
Twisted Prime Number:If a number is prime, and its reverse number is also prime,
then it is called Twisted prime number.
Example :- 37 is prime number , and its reverse order is 73 and 73 is also prime.
So Emirp number and twisted prime both same.
import java.util.*;
class twisted_prime
{
public static void main(String args[])
{
Scanner sg=new Scanner(System.in);
int a,s=0,r,num=0,c=0,c1=0;
System.out.println("Enter any no.");
a=sg.nextInt();
for(int i=1;i<=a;i++)
{
if(a%i==0)
c++;
}
if(c==2)
{
num=a;
}
while(num>0)
{
r=num%10;
s=s*10+r;
num=num/10;
}
for(int i=1;i<=s;i++)
{
if(s%i==0)
c1++;
}
if(c1==2)
System.out.println("Twisted prime");
else
System.out.println("Not Twisted prime");
}
}
Output:
Enter the no:
37
Twisted Prime.
Write a program in java to enter a number and check whether the number is emirp number or not .
An Emirp number is a number which is prime backwards and forwards.
Example: 13 and 31 are both prime numbers.Thus, 13 is an emirp number.
Twisted Prime Number:If a number is prime, and its reverse number is also prime,
then it is called Twisted prime number.
Example :- 37 is prime number , and its reverse order is 73 and 73 is also prime.
So Emirp number and twisted prime both same.
import java.util.*;
class twisted_prime
{
public static void main(String args[])
{
Scanner sg=new Scanner(System.in);
int a,s=0,r,num=0,c=0,c1=0;
System.out.println("Enter any no.");
a=sg.nextInt();
for(int i=1;i<=a;i++)
{
if(a%i==0)
c++;
}
if(c==2)
{
num=a;
}
while(num>0)
{
r=num%10;
s=s*10+r;
num=num/10;
}
for(int i=1;i<=s;i++)
{
if(s%i==0)
c1++;
}
if(c1==2)
System.out.println("Twisted prime");
else
System.out.println("Not Twisted prime");
}
}
Output:
Enter the no:
37
Twisted Prime.