Looking for the Risk Factor

Time limit0.2sMemory limit512 MB

Summary
Count integers in [2, N] whose prime factors are all at most K, for up to 50000 queries on N and K up to 100000.
Level

Hard8 of 10

Topics
Math, Number theory, Combinatorics, Brute force
Solved
No attempts yet

Problem

To test a new cryptographic algorithm, engineers working for a large investment bank need to compute a value they named the Risk Factor of the algorithm. Informally, the Risk Factor is the amount of numbers less than or equal to a certain value N that aren't multiples of prime numbers greater than a certain value K.

More formally, given the values N and K, the Risk Factor is the number of elements of the following set:

{x such that 2 ≤ x ≤ N and for every prime divisor p of x, p ≤ K}

The engineers need to compute the Risk Factor for different values of N and K and have prepared a set of queries for you to answer. Can you help them?

Input

The first line contains an integer Q (1 ≤ Q ≤ 5 × 104) representing the number of queries that the engineers prepared for you. Each of the following Q lines describes a query with two integers N and K (2 ≤ N, K ≤ 105).

Output

Output Q lines, each line with an integer indicating the Risk Factor for the corresponding query of the input.

Examples1

  1. Example 1

    Input
    4
    10 3
    10 4
    15 3
    5 20
    
    Expected output
    6
    6
    7
    4