Connection Status:
Competition Arena > PrimesBetween
Rookie SRM 12 · 2022-04-14 · by erinn · Brute Force
Class Name: PrimesBetween
Return Type: int
Method Name: count
Arg Types: (int, int)
Problem Statement

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?

Constraints

  • start will be between 1 and 100, inclusive.
  • end will be between start and 100, inclusive.
Examples
0)
2
11
Returns: 5

These are the primes listed in the problem statement.

1)
8
10
Returns: 0

Note that none of 8, 9, or 10, are prime, so we return 0.

2)
12
20
Returns: 3

The primes here are 13, 17, 19.

3)
1
100
Returns: 25
4)
20
30
Returns: 2

23 and 29.

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

Coding Area

Language: C++17 · define a public class PrimesBetween with a public method int count(int start, int end) · 6 test cases · 2 s / 256 MB per case

Submitting as anonymous