Statistics

Problem Statement for "PrimePalindromic"

Problem Statement

A palindrome is a string that reads the same forward and backward. An integer is called prime-palindromic if it is possible to construct a palindrome by concatenating all of its prime factors (without leading zeros). Each prime factor should be used as many times as its power in factorization. In other words if we have an positive integer N = p1w1 * ... * pMwM, where p1...pM are prime factors, then pJ must be used wJ times where J=1..M.

For example, 48 is prime-palindromic because its prime factors are 2, 2, 2, 2, 3 (2 should be used 4 times, 3 should be used once) and we can obtain the palindrome 22322. 2261 is prime-palindromic also because its prime factors are 7, 17, and 19, which can be concatenated to form the palindrome 71917. 2123 is not prime-palindromic because its prime factors are 11 and 193, and neither 11193 nor 19311 are palindromes. 33 is also not prime-palindromic (its prime factors are 3 and 11).

Return the number of prime-palindromic numbers between A and B, inclusive.

Definition

Class:
PrimePalindromic
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int A, int B)
(be sure your method is public)

Constraints

  • A will be between 2 and 10000, inclusive.
  • B will be between A and 10000, inclusive.

Examples

  1. 2260

    2262

    Returns: 1

    The only prime-palindromic number is 2261.

  2. 2

    9

    Returns: 7

    All numbers except 6 are prime-palindromic.

  3. 2

    100

    Returns: 36

  4. 2

    10000

    Returns: 728

  5. 2

    1000

    Returns: 175

  6. 1001

    2000

    Returns: 87

  7. 2001

    3000

    Returns: 74

  8. 3001

    4000

    Returns: 77

  9. 4001

    5000

    Returns: 64

  10. 5001

    6000

    Returns: 59

  11. 6001

    7000

    Returns: 56

  12. 7001

    8000

    Returns: 41

  13. 8001

    9000

    Returns: 49

  14. 9001

    10000

    Returns: 46

  15. 2

    2

    Returns: 1

  16. 10000

    10000

    Returns: 1

  17. 18

    9973

    Returns: 716

  18. 123

    7711

    Returns: 578

  19. 1723

    4455

    Returns: 197

  20. 8899

    9988

    Returns: 49

  21. 4878

    9951

    Returns: 256

  22. 1111

    9999

    Returns: 541

  23. 8712

    9827

    Returns: 51

  24. 100

    10000

    Returns: 693

  25. 99

    5001

    Returns: 443

  26. 1023

    8191

    Returns: 469

  27. 2

    10000

    Returns: 728

  28. 2

    100

    Returns: 36


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: