This page is still under construction.

Parts of this page are still being built. What you see may change.

The Lost Fraction

Time limit1sMemory limit128 MB

Summary
Given n and a, list every reduced fraction with denominator at most n that lies in the closed interval [a/n^2, (a+1)/n^2], in increasing order.
Level

Hard8 of 10

Topics
Number theory, Math, Binary search
Solved
No attempts yet

Problem

Byteasar came up with a really neat fraction whose denominator is at most nn, but after a while he forgot which fraction it was. He is almost certain that it lay inside the closed interval [an2,a+1n2]\left[\frac{a}{n^2}, \frac{a+1}{n^2}\right]. Help him by finding every fraction inside this interval whose denominator is at most nn.

Here a fraction "with denominator at most nn" means a rational number whose denominator, once the fraction is reduced to lowest terms, is at most nn. Both endpoints of the interval are included.

Input

The only line contains two integers nn and aa separated by a single space (1≤n<2321 \le n < 2^{32}, 1≤a<264−11 \le a < 2^{64}-1).

Output

On the first line print mm, the number of distinct reduced fractions that lie in the interval [an2,a+1n2]\left[\frac{a}{n^2}, \frac{a+1}{n^2}\right] and have denominator at most nn.

On each of the following mm lines print the numerator and the denominator of one such fraction, separated by a single space. Every fraction must be written in lowest terms, and the fractions must be listed in strictly increasing order of their value.

Examples1

  1. Example 1

    Input
    5 43
    
    Expected output
    1
    7 4