#P8039. [COCI 2016/2017 #7] UZASTOPNI

[COCI 2016/2017 #7] UZASTOPNI

Background

The only differences between this problem and P1147 are the range of the sum of consecutive natural numbers and the output format.

Problem Description

Find all consecutive segments of natural numbers with length 2\geqslant 2 whose sum is NN.

Input Format

The input contains only one line with an integer NN, which represents the sum of the consecutive natural number segment.

Output Format

Output several lines. Each line contains two integers, representing the first number and the last number of a valid consecutive natural number segment, sorted in descending order by the first number.

For the given input, it is guaranteed that there is at least one solution.

10
1 4
27
13 14
8 10
2 7

Hint

[Sample 1 Explanation]

10=1+2+3+410=1+2+3+4. We can see that there is one and only one consecutive natural number segment whose sum is 1010 and satisfies the requirements.

[Constraints]

For all testdata, 3N10103\leqslant N\leqslant 10^{10}.

[Source]

This problem is from COCI 2016-2017 CONTEST 7 T2 UZASTOPNI. With the original problem's data settings, the full score is 8080 points.

Translated and organized by Eason_AC.

Translated by ChatGPT 5