TopcoderArchive
SRM21 Feb 2006
SRM 291

FarFromPrimes

Problem statement, definition, constraints, and public examples.

Problem Statement

A prime number is an integer greater than 1 that has no positive divisors other than 1 and itself. The first prime numbers are 2, 3, 5, 7, 11, 13, 17, ...

The number N is considered far from primes if there are no prime numbers between N-10 and N+10, inclusive, i.e., all numbers N-10, N-9, ..., N-1, N, N+1, ..., N+9, N+10 are not prime.

You are given an int A and an int B. Return the number of far from primes numbers between A and B, inclusive.

Definition

Class:
FarFromPrimes
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 10 and 100000, inclusive.
  • B will be between A and 100000, inclusive.
  • (B - A) will be between 0 and 1000, inclusive.

Examples

  1. 3328
    4100
    Returns: 4
    The far from primes numbers are 3480, 3750, 3978 and 4038.
  2. 10
    1000
    Returns: 0
  3. 19240
    19710
    Returns: 53
  4. 23659
    24065
    Returns: 20
  5. 97001
    97691
    Returns: 89
Back to all problems