Triangular Dependencies A triangular number is a number that is the sum of n natural numbers from 1 to n. For example 1 + 2 + 3 + 4 = 10 so 10 is a triangular number.

Given a positive integer (0 &lt; n &lt;= 10000) as input (can be taken as an integer, or as a string), return the smallest possible triangular number that can be added to the input to create another triangular number.

For example given input 26, adding 10 results in 36, which is also a triangular number. There are no triangular numbers smaller than 10 that can be added to 26 to create another triangular number, so 10 is the correct result in this case.

0 is a triangular number, therefore if the input is itself a triangular number, the output should be 0

Testcases

Cases are given in the format input -&gt; output (resulting triangular number)

0     -&gt; 0   (0)
4     -&gt; 6   (10)
5     -&gt; 1   (6)
7     -&gt; 3   (10)
8     -&gt; 28  (36)
10    -&gt; 0   (10)
24    -&gt; 21  (45)
25    -&gt; 3   (28)
26    -&gt; 10  (36)
34    -&gt; 21  (55)
10000 -&gt; 153 (10153)


Scoring

This is code-golf so fewest bytes in each language wins!
Java 8, 58 57 bytes



n-&gt;{int i=0,m=0;while(n!=0)n+=n&lt;0?++i:--m;return-~i*i/2;}


Online test suite

Thanks to Dennis for a 1-byte saving.