Statistics

Problem Statement for "PalindromePrime"

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 two ints: L and R. Compute and return the number of palindromic primes between L and R, inclusive.

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

  1. 100

    150

    Returns: 2

    This range contains only two palindromic primes: 101 and 131.

  2. 1

    9

    Returns: 4

    The palindromic primes in this range are 2, 3, 5, and 7.

  3. 929

    929

    Returns: 1

  4. 1

    1

    Returns: 0

  5. 1

    1000

    Returns: 20

  6. 12

    342

    Returns: 6

  7. 200

    300

    Returns: 0

  8. 900

    929

    Returns: 2

  9. 900

    939

    Returns: 2

  10. 900

    928

    Returns: 1

  11. 900

    930

    Returns: 2

  12. 23

    43

    Returns: 0

  13. 23

    928

    Returns: 14

  14. 442

    928

    Returns: 5

  15. 99

    102

    Returns: 1

  16. 5

    1000

    Returns: 18

  17. 33

    33

    Returns: 0

  18. 1

    100

    Returns: 5

  19. 928

    929

    Returns: 1

  20. 2

    2

    Returns: 1

  21. 22

    22

    Returns: 0

  22. 88

    101

    Returns: 1

  23. 1

    5

    Returns: 3

  24. 10

    100

    Returns: 1

  25. 3

    3

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: