infO(1) Cup 2024 Mirror - Day 2 | Lattice

This was the problem page during the contest. Access the current page here.
Time limit: 0.5s Memory limit: 512MB Input: Output:

For every two positive integers N,M,N, M, we define lattice(N,M)lattice(N, M) to be those points (x,y)(x, y) for which NN divides xx and MM divides yy, and where x,yx, y are non-negative integers. In other words, the points of lattice(N,M)lattice(N, M) can be thought of as those points reachable from (0,0)(0, 0) by moving a multiple of NN steps to the right, and a multiple of MM steps up. For example, lattice(2,3)lattice(2, 3) looks like this.

Task

Given KK and a list of PP points (x1,y1),,(xP,yP)(x_1, y_1), \dots , (x_P, y_P) with integer coordinates in the plane, answer the following question: For how many positive integers xx does lattice(x,x)lattice(x, x) contain at least KK of the PP points?

Input data

The first line of the input contains PP and KK. The next PP lines contain the points (xi,yi)(x_i, y_i).

Output data

The first line of the output should contain the answer to the question.

Restrictions

  • 1xi,yi1 000 0001 \leq x_i, y_i \leq 1 \ 000 \ 000
  • 1KP200 0001 \leq K \leq P \leq 200 \ 000
# Points Restrictions
1 16 All the values from input are at most 1 0001 \ 000
2 11 All the values from input are at most 100 000100 \ 000
3 15 xi=yix_i = y_i for all the points
4 21 The sequence x1,,xP,y1,,yPx_1, \dots , x_P, y_1, \dots , y_P contains pairwise distinct elements.
5 37 No further restrictions.

Example 1

stdin

3 2
1 3
3 6
4 2

stdout

1

Explanation

In the first example, only lattice(1,1)lattice(1, 1) contains at least 22 points.

Example 2

stdin

5 2
2 2
5 10
6 4
15 5
1 7

stdout

3

Explanation

Here, lattice(1,1)lattice(1, 1) contains all the points, lattice(2,2)lattice(2, 2) has the first and the third point and lattice(5,5)lattice(5, 5) has the second and the fourth point. Below is a grid showing all the lattices. lattice(1,1)lattice(1, 1) is the underlying grid, lattice(2,2)lattice(2, 2) is marked by red x’s\color{red}\text{red x’s}, and lattice(5,5)lattice(5, 5) is marked by blue x’s\color{blue}\text{blue x’s}. The points in all three lattices are marked by purple x’s\color{purple}\text{purple x’s}. The PP points in the input are marked by filled-in circles ()(•), with the colour showing which grid they belong to: if a point is only in lattice(1,1)lattice(1, 1) it is gray\color{gray}\text{gray}, if it is in lattice(1,1)lattice(1, 1) and lattice(2,2)lattice(2, 2) it is red\color{red}\text{red}, and if it is in lattice(1,1)lattice(1, 1) and lattice(5,5)lattice(5, 5) it is blue\color{blue}\text{blue}.

Log in or sign up to be able to send submissions!