Given two numbers L and R which signifies a range [L, R], the task is to print all the prime adam integers in this range.
Note: A number which is both prime, as well as adam, is known as a prime adam number.
Input: L = 5, R = 100
Output: 11 13 31
The three numbers 11, 13, 31 are prime. They are also adam numbers.
Input: L = 70, R = 50
Output: Invalid Input
Approach: The idea used in this problem is to first check whether a number is prime or not. If it is prime, then check whether it is an adam number of not:
- Iterate through the given range [L, R].
- For every number, check if the number is prime or not.
- If it is a prime, then check whether the number is an adam number or not.
- If a number is both prime and adam, then print the number.
Below is the implementation of the above approach:
11 13 31
Time Complexity: O(N2), where N is the maximum number R.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Adam Number
- Permutation of first N positive integers such that prime numbers are at prime indices
- Permutation of first N positive integers such that prime numbers are at prime indices | Set 2
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Count all prime numbers in a given range whose sum of digits is also prime
- Count numbers in a given range whose count of prime factors is a Prime Number
- Generate a pair of integers from a range [L, R] whose LCM also lies within the range
- Count pairs from a given range whose sum is a Prime Number in that range
- Find the prime P using given four integers
- Find sum in range L to R in given sequence of integers
- Find two co-prime integers such that the first divides A and the second divides B
- Median in a stream of integers (running integers)
- Mode in a stream of integers (running integers)
- Lexicographically smallest permutation of size A having B integers exceeding all preceeding integers
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Find pair with maximum GCD for integers in range 2 to N
- Find and Count total factors of co-prime A or B in a given range 1 to N
- C/C++ Program to find Prime Numbers between given range
- Ways to form an array having integers in given range such that total sum is divisible by 2
- Generate Bitonic Sequence of length N from integers in a given range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.