Fractions
Time limit2sMemory limit512 MB
Given n, represent 1 - 1/n as a sum of fractions with denominators dividing n and strictly between 1 and n, or report that no such sum exists.
- Level
Hard8 of 10
- Topics
- Math, Number theory, Greedy, Implementation
- Solved
- No attempts yet
Problem
You are given a positive integer .
Find a sequence of fractions (, where and are positive integers) for some such that
[\begin{cases} b_i \text{ divides } n, 1 < b_i < n \text{ for } i = 1 \dots k \ 1 \le a_i < b_i, \text{ for } i = 1 \dots k \ \sum_{i=1}^{k}{\frac{a_i}{b_i}} = 1 - \frac{1}{n} \end{cases}]
Input
The input consists of a single integer ().
Output
On the first line print "YES" if such a sequence of fractions exists, or "NO" otherwise.
If such a sequence exists, the following lines describe the sequence in this format.
The second line contains the integer (), the number of elements in the sequence. If such a sequence exists, a sequence of length at most is guaranteed to exist. The next lines contain the fractions of the sequence, with two integers and on each line.
Hint
The second example has the sequence , , and .