Problem Statement
A positive integer is called a prime if it has exactly two distinct positive integer divisors: 1 and itself.
The first few primes are 2, 3, 5, 7, 11, 13, ...
A positive integer is called a palindrome if its base-10 representation reads the same forwards and backwards. Some palindromes: 2, 77, 101, 33333, 12344321.
A positive integer is called a palindromic prime if it is both a palindrome and a prime.
You are given twoint s: L and R.
Compute and return the number of palindromic primes between L and R, inclusive.
A positive integer is called a palindrome if its base-10 representation reads the same forwards and backwards. Some palindromes: 2, 77, 101, 33333, 12344321.
A positive integer is called a palindromic prime if it is both a palindrome and a prime.
You are given two
Definition
- Class:
- PalindromePrime
- Method:
- count
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int count(int L, int R)
- (be sure your method is public)
Notes
- The number 1 is not a prime number.
Constraints
- L will be between 1 and 1,000, inclusive.
- R will be between L and 1,000, inclusive.
Examples
100
150
Returns: 2
This range contains only two palindromic primes: 101 and 131.
1
9
Returns: 4
The palindromic primes in this range are 2, 3, 5, and 7.
929
929
Returns: 1
1
1
Returns: 0
1
1000
Returns: 20
12
342
Returns: 6
200
300
Returns: 0
900
929
Returns: 2
900
939
Returns: 2
900
928
Returns: 1
900
930
Returns: 2
23
43
Returns: 0
23
928
Returns: 14
442
928
Returns: 5
99
102
Returns: 1
5
1000
Returns: 18
33
33
Returns: 0
1
100
Returns: 5
928
929
Returns: 1
2
2
Returns: 1
22
22
Returns: 0
88
101
Returns: 1
1
5
Returns: 3
10
100
Returns: 1
3
3
Returns: 1