# Program to determine whether a given number is a twisted prime number

Program to determine whether a given number is a twisted prime number on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph, pattern, string etc.

## Program to determine whether a given number is a twisted prime number

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

The algorithm to check whether a given number is a twisted prime number is given below.

### Algorithm

• STEP 1: START
• STEP 2: DEFINE n, reverse, flag
• STEP 3: SET sum = 0
• STEP 4: ENTER n
• STEP 5: REPEAT STEP 6 to 8 UNTIL (n!=0)
• STEP 6: reverse = n%10
• STEP 7: sum = sum*10 + reverse
• STEP 8: n = n/10
• STEP 9: SET flag =0
• STEP 10: REPEAT STEP 11 UNTIL j<=sum/2
• STEP 11: if(sum%j)==0
then
set flag = 1
break
• STEP 12: if(flag==0)
then PRINT "yes"
else
PRINT "no"
• STEP 13: END

### Java Program

```import java.util.*;
class Twisted_Prime
{
public static void main(String[] args)
{

int n, reverse,sum=0 , flag;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the prime number?");
n = sc.nextInt();

while(n!=0)
{
reverse = n%10;
sum = sum*10 + reverse;
n= n/10;
}

flag = 0;
for (int j = 2; j <= sum / 2; j++)
{
if ((sum % j) == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
System.out.println("Twisted Prime");
else
System.out.println("Not Twisted Prime");
}
}
```

Output:

```Enter the prime number?
43
Not Twisted Prime
```

### Python Program

```n=int(input("Enter the prime number?"))
rev=0
flag=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
for j in range(2, rev//2):
if ((rev % j) == 0):
flag = 1
break
if (flag == 0):
print("Twisted Prime")
else:
print("Not Twisted Prime")
```

Output:

```Enter the prime number?
13
Twisted Prime
```

### C Program

```#include <stdio.h>
int main()
{
int n, reverse,sum=0 , flag;
printf("Enter the prime number?");
scanf("%d",&n);
while(n!=0)
{
reverse = n%10;
sum = sum*10 + reverse;
n= n/10;
}

printf("\n");
flag = 0;
for (int j = 2; j <= sum / 2; j++)
{
if ((sum % j) == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
printf("Twisted Prime");
else
printf("Not Twisted Prime");

}
```

Output:

```Enter the prime number?
11
Twisted Prime
```

### C# program

```using System;
{
public static void Main()
{

int n, reverse,sum=0 , flag;
Console.WriteLine("Enter the prime number?");

while(n!=0)
{
reverse = n%10;
sum = sum*10 + reverse;
n= n/10;
}

flag = 0;
for (int j = 2; j <= sum / 2; j++)
{
if ((sum % j) == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
Console.WriteLine("Twisted Prime");
else
Console.WriteLine("Not Twisted Prime");
}}
```

Output:

```            Enter the prime number?
13
Twisted Prime
```

### PHP Program

```<?php
echo "Enter the prime number?";
\$sum=0;
while(\$n!=0)
{
\$reverse = \$n%10;
\$sum = \$sum*10 + \$reverse;
\$n= \$n/10;
}
\$flag = 0;
for (\$j = 2; \$j <= \$sum / 2; \$j++)
{
if ((\$sum % \$j) == 0)
{
\$flag = 1;
break;
}
}
if (\$flag == 0)
echo ("Twisted Prime");
else
echo("Not Twisted Prime");
?>
```

Output:

```             Enter the prime number?
17
Twisted Prime
```
Next Topic#