Connection Status:
Competition Arena > FarFromPrimes
SRM 291 · 2006-02-21 · by Andrew_Lazarev · Brute Force, Math
Class Name: FarFromPrimes
Return Type: int
Method Name: count
Arg Types: (int, int)
Problem Statement

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.

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

Submissions are judged against all 103 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class FarFromPrimes with a public method int count(int A, int B) · 103 test cases · 2 s / 256 MB per case

Submitting as anonymous