Here is the code for prime test using √n approach
static boolean isPrime(nt">int n){
//corner case
if (n <= 1) return false;
if (n <= 3) return true;
//middle 5 number
if (n % 2 == 0 || n % 3 == 0) return false;
for (nt">int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
Use can use set
for remove duplicate element
manpreet
Best Answer
2 years ago
Write a program to read n ref="https://forum.tuteehub.com/tag/numbers">numbers. The first number specified as input will be n. Next, the program should read n integer ref="https://forum.tuteehub.com/tag/numbers">numbers.
The program should check for each number if it is prime as well as if its reverse is prime.
Display all such ref="https://forum.tuteehub.com/tag/numbers">numbers in ascending order.
Consider below example for input and output:
Input: 7 11 12 23 19 7 113 101
Output:
7 11 101 113
My code