Jeongmin's Sequence Recipe
Time limit1sMemory limit1024 MB
For each query [a, b], count the starting integers in range, where the starting set is 1 plus all primes up to N.
- Level
Medium4 of 10
- Topics
- Math, Number theory, Prefix sum
- Solved
- No attempts yet
문제
Jeongmin wants to build a sequence that contains each integer from 1 to exactly once. To do this, he prepared a sequence of positive integers with the smallest possible count, then repeated the following operations until he reached the goal.
- Add the square of an integer in the sequence to the sequence.
- Add the product of two integers in the sequence to the sequence.
After finishing all the operations, Ikjun asked Jeongmin which integers he had started with. Instead of answering, Jeongmin said that whenever Ikjun gives and , he would tell the number of initial integers between and , inclusive. Ikjun will ask questions in total.
Answer Ikjun's questions.
입력
The first line contains integers and , separated by a space. (; )
From the second line, lines follow, each containing integers and separated by a space. ()
출력
Print the answer to each question on its own line, lines in total.
힌트
Python 3 users are recommended to submit with PyPy3.