The Game

Time limit1sMemory limit128 MB

Summary
Given N and a count M of 'I don't know' answers, find all pairs the master could have chosen in the sum-product guessing game.
Level

Medium7 of 10

Topics
Simulation, Math, Implementation, Brute force
Solved
No attempts yet

Problem

There is a legend that in the 18th century mathematicians enjoyed the following game.

Three mathematicians take part, and one of them is the game master. The game master first announces a positive integer NN. He then secretly chooses two different integers XX and YY, each between 11 and NN inclusive, and privately tells their sum X+YX + Y to player SS and their product X⋅YX \cdot Y to player PP. Each player learns only their own value and knows whether it is the sum or the product.

The two players then speak in turns, always in the fixed order SS, PP, SS, PP, …\dots — player SS always speaks first. On each turn the current player announces either "I know these numbers" or "I don't know these numbers", reasoning only from their own value and from every statement made so far (all statements are public). A player can name the pair exactly when only one pair is still consistent with everything known. The game ends the instant a player says "I know".

For example, the dialog might go like this:

  • Game master: "Let NN be 1010." (then he chooses two numbers from 11 to 1010 and tells their sum to SS and their product to PP)
  • Player SS: "I don't know these numbers."
  • Player PP: "I don't know these numbers."
  • Player SS: "I don't know these numbers."
  • Player PP: "I don't know these numbers."
  • Player SS: "Now I know these numbers — you chose 33 and 66."

You are given NN and MM, where MM is the total number of times "I don't know these numbers" was said before the game ended (so the final "I know" is statement number M+1M + 1). Find every pair of numbers the game master could have chosen.

Input

One line with two integers NN and MM (2≤N≤2002 \le N \le 200, 0≤M≤1000 \le M \le 100).

Output

On the first line, print the number of pairs the game master could have chosen from 11 to NN so that the players said "I don't know these numbers" exactly MM times before someone said "I know".

Then print those pairs, one per line, each as two integers "aa bb" with a<ba < b. Print the pairs in ascending order: sorted by the first number, and by the second number when the first numbers are equal.

Examples3

  1. Example 1

    Input
    10 4
    
    Expected output
    3
    2 5
    3 6
    3 10
    
  2. Example 2

    Input
    10 0
    
    Expected output
    4
    1 2
    1 3
    8 10
    9 10
    
  3. Example 3

    Input
    10 5
    
    Expected output
    3
    1 10
    2 9
    5 6