Prime check
Statement
We want to decide, for every natural number between A and B inclusive, whether it is prime. Here A is a natural number between 100,000,000 and 100,010,000, and B is a natural number between A and 100,010,000.
Given A and B, write a program that counts the primes among all natural numbers between A and B inclusive.
For example, suppose the value of A is 100,000,005 and the value of B is 100,000,010. The table below shows, for each natural number between A and B inclusive, whether it is prime. A prime is recorded as true (T) and a number that is not prime as false (F).
| Value | Prime |
|---|---|
| 100000005 | F |
| 100000006 | F |
| 100000007 | T |
| 100000008 | F |
| 100000009 | F |
| 100000010 | F |
So in this example the number of primes among all natural numbers between A and B inclusive (the answer) is 1.
Input and Output Examples
Example 1
Input
100000000, 100000000
Output
0
Example 2
Input
100000000, 100000007
Output
1
Example 3
Input
100008572, 100009233
Output
31
Input
A and B are given in order as natural numbers. Here A is a natural number between 100,000,000 and 100,010,000, and B is a natural number between A and 100,010,000.
Output
Return the number of primes among all natural numbers between A and B inclusive.
Requirements
- You must write a solution(A, B) function and return the answer
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- There are 15 cases, and 6 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 15 cases to solve this.
Examples
6 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.
100000000, 100000000
0
100000000, 100000007
1
100008572, 100009233
31
100000081, 100009639
524
100001863, 100008623
379
100001634, 100009946
462
Notes
Background that helps with solving. The rules you have to follow are in the input and output specs and the requirements above.
This is problem 1 of practice test 8 in the original.
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 6 public cases. Submitting runs the hidden cases too.
People who solved this problem
The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.
Input read time 4ms (excluded from the ranking)
Log in and you can see the code once you solve this problem.