Under construction

Still being built. Things may change

Jeongmin's Sequence Recipe

Time limit1sMemory limit1024 MB

Summary
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 NN 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 aa and bb, he would tell the number of initial integers between aa and bb, inclusive. Ikjun will ask MM questions in total.

Answer Ikjun's questions.

입력

The first line contains integers NN and MM, separated by a space. (1≤N≤50000001 \le N \le 5000000; 1≤M≤10000001 \le M \le 1000000)

From the second line, MM lines follow, each containing integers aa and bb separated by a space. (1≤a≤b≤N1 \le a \le b \le N)

출력

Print the answer to each question on its own line, MM lines in total.

힌트

Python 3 users are recommended to submit with PyPy3.

Examples2

  1. Example 1

    Input
    50 4
    1 15
    5 6
    20 40
    40 50
    
    Expected output
    7
    1
    4
    3
    
  2. Example 2

    Input
    5000000 5
    2 10
    2 3
    2 5000000
    3 10000
    5 5
    
    Expected output
    4
    2
    348513
    1228
    1