Under construction

Still being built. Things may change

Binomial Coefficient

Time limit1sMemory limit128 MB

Summary
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 kk items from nn distinct items without regard to order, and is defined as follows.

(nk)=n!k! (n−k)!(0≤k≤n)\binom{n}{k} = \frac{n!}{k!\,(n-k)!} \quad (0 \le k \le n)

Two people play a binomial-coefficient guessing game. One says an integer mm, and the other must find every pair of integers (n,k)(n, k) such that (nk)=m\binom{n}{k} = m. For example, if m=15m = 15, then (62)\binom{6}{2}, (64)\binom{6}{4}, (151)\binom{15}{1}, and (1514)\binom{15}{14} all equal 1515, so the answer is (6,2)(6, 2), (6,4)(6, 4), (15,1)(15, 1), (15,14)(15, 14).

Given an integer mm, write a program that finds all pairs (n,k)(n, k) satisfying (nk)=m\binom{n}{k} = m. For every mm in the input, at least one such binomial coefficient exists.

Input

The first line contains an integer mm. (2≤m≤10152 \le m \le 10^{15})

Output

On the first line, print the number of pairs (n,k)(n, k) satisfying (nk)=m\binom{n}{k} = m. On each of the following lines, print one pair: nn and kk separated by a space. Print the pairs in increasing order of nn; when nn is equal, in increasing order of kk.

Examples1

  1. Example 1

    Input
    15
    
    Expected output
    4
    6 2
    6 4
    15 1
    15 14