Binomial Coefficient
Time limit1sMemory limit128 MB
Given m up to 10^15, find all pairs (n,k) with binomial coefficient n choose k equal to m, listed in sorted order.
- Level
Medium7 of 10
- Topics
- Math, Combinatorics, Binary search
- Solved
- No attempts yet
Problem
The binomial coefficient is the number of ways to choose items from distinct items without regard to order, and is defined as follows.
Two people play a binomial-coefficient guessing game. One says an integer , and the other must find every pair of integers such that . For example, if , then , , , and all equal , so the answer is , , , .
Given an integer , write a program that finds all pairs satisfying . For every in the input, at least one such binomial coefficient exists.
Input
The first line contains an integer . ()
Output
On the first line, print the number of pairs satisfying . On each of the following lines, print one pair: and separated by a space. Print the pairs in increasing order of ; when is equal, in increasing order of .