


1.’Left’ and ‘Right’ both are inclusive in the range ‘Left’ to ‘Right’.
‘Left’ = ‘23’ and ‘Right’ = ‘37’

All prime numbers from ‘23’ to ‘37’ are 23, 29, 31, 37
23 is ‘megaprime’ number because ‘2’ and ‘3’ both are prime
29 is not ‘megaprime’ number because ‘9’ is not a prime
31 is not a ‘megaprime’ number because ‘1’ is not a prime number
37 is ‘megaprime’ number because ‘3’ and ‘7’ both are prime numbers
Hence there are two ‘megaprime’ numbers 23, 37 out of 23, 29, 31, 37.
The first line of input contains an integer ‘T’ denoting the number of test cases
Next ‘T’ lines contain two space-separated integers ‘Left’ and ‘Right’ which represent the next ‘T’ test cases.
For each test case, print an integer denoting the total count of ‘megaprime’ numbers.
You need not to print anything. It has been already taken care of. Just implement the function.
1 <= T <= 100
1 <= Left <= Right <= 8000
Time Limit: 1 sec
The idea is to check every number from ‘Left’ to ‘Right’ whether it is prime or not. If the number isprime, then check for its individual digits.
The idea is to pre-compute whether the numbers from ‘1’ to ‘Right’ ( given second integer ) are prime or not, so that we need not check the number for being prime or not, every time.
In this approach, we try to modify the ‘Sieve of Eratosthenes algorithm’. For every number ‘i’ where ‘i’ is 2 to ‘Right-1’, check if ‘i’ is prime or not. If yes, then store it into ‘primeArr’. For every prime number ‘j’ and ‘j’ is less than or equal to the smallest prime factor ‘p’ of ‘i’. Mark all numbers ‘j*p’ to non-prime.
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers