TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

PrimeNumThm

Problem statement, definition, constraints, and public examples.

Problem Statement

The Prime Number Theorem describes the density of prime numbers. Your program is going to help test this theorem.
A number is prime if it is greater than 1, and is only evenly divisible by itself and 1. Given ints lower and upper you will return how many primes there are between lower and upper inclusive.

Definition

Class:
PrimeNumThm
Method:
howMany
Parameters:
int, int
Returns:
int
Method signature:
int howMany(int lower, int upper)
(be sure your method is public)

Constraints

  • lower will be between 2 and 5000000 inclusive.
  • upper will be between 2 and 5000000 inclusive.
  • lower will be at most upper.

Examples

  1. 2
    5
    Returns: 3
    2, 3, and 5 are prime
  2. 7
    7
    Returns: 1
    7 is prime
  3. 14
    16
    Returns: 0
    No primes here
  4. 2
    1000
    Returns: 168
  5. 2
    5000000
    Returns: 348513
Back to all problems