TopcoderARCHIVE
Archive/Problems/PrimesBetween
SRM · Problem 17554

PrimesBetween

Problem statement, definition, constraints, and public examples.

Problem Statement

A prime number is one that has exactly two divisors: 1 and itself. The first few primes are 2, 3, 5, 7, 11.

Given start and end, how many prime numbers are there between those bounds, inclusive?

Definition

Class:
PrimesBetween
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int start, int end)
(be sure your method is public)

Constraints

  • start will be between 1 and 100, inclusive.
  • end will be between start and 100, inclusive.

Examples

  1. 2
    11
    Returns: 5
    These are the primes listed in the problem statement.
  2. 8
    10
    Returns: 0
    Note that none of 8, 9, or 10, are prime, so we return 0.
  3. 12
    20
    Returns: 3
    The primes here are 13, 17, 19.
  4. 20
    30
    Returns: 2
    23 and 29.
← All problems