#P5077. Minimal First Term of an Arithmetic Sequence Summing to s

    ID: 18315 Type: Default 1000ms 256MiB

Minimal First Term of an Arithmetic Sequence Summing to s

Minimal First Term of an Arithmetic Sequence Summing to s

Tweetuzki loves arithmetic sequences, in particular those with a common difference of \(1\) and consisting of positive integers. For any given positive integer \(s\), there exists an arithmetic sequence of the form \(a, a+1, \ldots, a+(n-1)\) such that the sum

[ s = n \cdot a + \frac{n(n-1)}{2} ]

holds for some positive integer \(n\). Among all valid representations of \(s\) in this form, your task is to compute the minimum possible value of the first term \(a\). Note that \(a\) must be a positive integer.

inputFormat

The input consists of a single integer \(s\) \( (1 \leq s \leq 10^{12}) \), representing the sum of the arithmetic sequence.

outputFormat

Output a single integer: the minimum possible first term \(a\) of the arithmetic sequence that sums to \(s\) with a common difference of \(1\).

sample

10
1