TopcoderArchive
Archive
Algorithm problem

AlmostPrime

Problem statement, definition, constraints, and public examples.

Problem Statement

A number is called "almost prime" if it is a power of a prime number, but is not a prime number itself. Note that 1 is not almost prime. You are given two Strings A and B, both representing integers (without leading zeros). Return the number of integers between A and B, inclusive, that are almost prime.

Definition

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

Constraints

  • A will represent an integer between 1 and 10^14, inclusive.
  • B will represent an integer between A and 10^14, inclusive.
  • Both A and B will have no leading zeros.

Examples

  1. "1"
    "10"
    Returns: 3
    4, 8 and 9 are almost prime here.
  2. "1"
    "1000"
    Returns: 25
  3. "5324"
    "894739"
    Returns: 183
Back to all problems