PalindromePrime
SRM 677 · 2015-11-03 · by cgy4ever
SRM 677 · 2015-11-03 · by cgy4ever · Brute Force
Problem Statement
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
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
0)
100 150 Returns: 2
This range contains only two palindromic primes: 101 and 131.
1)
1 9 Returns: 4
The palindromic primes in this range are 2, 3, 5, and 7.
2)
929 929 Returns: 1
3)
1 1 Returns: 0
4)
1 1000 Returns: 20
Submissions are judged against all 25 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class PalindromePrime with a public method int count(int L, int R) · 25 test cases · 2 s / 256 MB per case