TopCoder problem "FarFromPrimes" used in SRM 291 (Division II Level One)



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

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

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6074

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=9812&pm=6074

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Brute Force, Math