TITLE: Minimum of $n$? $123456789x^2 - 987654321y^2 =n$ ($x$,$y$ and $n$ are positive integers)
QUESTION [25 upvotes]: What is the minimum of $n$?
$x$,$y$ and $n$ are positive integers, find the minimum of $n$, such that:

$123456789x^2 - 987654321y^2 =n$

REPLY [6 votes]: EEEDDDIIITTT: The five (primitively represented) smallest positive values and five smallest negative (in absolute value). The method was complete by the time of Lagrange, uses no computer memory at all, no decimal accuracy (only integer operations), no cycle detection, no guesswork. It also takes about one minute of human time to go through the full cycle of 3,861,006 neighboring forms.
$$-1521, \; 
-1089, \;
-900, \;
-729, \;
-225, \;
495, \;
621, \;
1053, \;
1395, \;
1845.$$
EDIT: I posted a proof of the "riverbend" property at Generate solutions of Quadratic Diophantine Equation
EEDDIITT:: a fair portion of the necessary material is in BUCHMANN_VOLLMER, especially a (revised) Lagrange method on pages 129-130, and the fact that the minimum occurs in the cycle is Corollary 6.16.2 on page 139. For some reason they do not prove the full Lagrange theorem, that all small values that are primitively represented occur as coefficients of forms in the cycle. Not my fault.  
I finally wrote an implementation of Lagrange's cycle method with everything in C++ using GMP integers. Here is what happens, only the forms are printed that achieve a new low in absolute value, one comparison for negative values, one for positive. The key point is Lagrange's theorem, page 111, Theorem 85, in Introduction to the Theory of Numbers by Leonard Eugene Dickson, that, given and indefinite form $\langle a,b,c \rangle$ or $f(x,y) = a x^2 + b x y + c y^2,$ with discriminant $\Delta = b^2 - 4 a c$ positive but not a square, then all integers $n$ with $|n| < \frac{1}{2} \sqrt \Delta$ primitively represented by $f(x,y)$ occur as the first coefficient in the chain of reduced forms equivalent to $f.$ A comparison of Lagrange's method, put briefly in pages 21-24 of Binary Quadratic Forms by Duncan A. Buell, with Conway's topograph method, reveals that Lagrange reduced forms are precisely those with $$ ac < 0, \; \; b > |a+c| $$ and that furthermore, these are precisely the locations where the forms "cross the river." Marty Weissmann calls these riverbends.
For the example below, the discriminant and the floor of the square root of it are DISCRIMINANT  487730524450541076    DISC SQRT  698377064.
jagy@phobeusjunior:~$ date
Sat Jul 13 22:12:41 PDT 2013
jagy@phobeusjunior:~$ 
jagy@phobeusjunior:~$ ./indef_Binary
Input three coefficients a b c for indef f(x,y)= a x^2 + b x y + c y^2 
 123456789  0  -987654321  

123456789  b   0  c  -987654321
 A  -987654321 B  0 C  123456789
 A  123456789 B  493827156 C  -493827165


 continue? 
1

0  form    A  123456789 B  493827156 C  -493827165
2  form    A  123456780 B  493827066 C  -493827381
4  form    A  123456465 B  493824024 C  -493834725
6  form    A  123445764 B  493720686 C  -494084205
8  form    A  123082245 B  490210236 C  -502559181
10  form    A  110733300 B  592424874 C  -308767311
11  form    A  -308767311 B  642644370 C  60513804
12  form    A  60513804 B  688659318 C  -55685097
13  form    A  -55685097 B  647783010 C  305771652
17  form    A  -21823083 B  690335820 C  127926243
22  form    A  26835705 B  681544296 C  -216389853
40  form    A  25032753 B  693227718 C  -71564796
50  form    A  18112023 B  672657678 C  -486723276
61  form    A  -3389724 B  694535274 C  394669125
66  form    A  9592524 B  687423006 C  -395624115
80  form    A  4696569 B  694689462 C  -273448332
106  form    A  2052108 B  697133610 C  -211398993
559  form    A  -2164257 B  697795578 C  93779964
605  form    A  -1504620 B  696400506 C  458065773
761  form    A  -836676 B  696763278 C  672739173
1038  form    A  1814724 B  695167830 C  -616100931
1511  form    A  -716175 B  697643424 C  357516459
1636  form    A  68508 B  698257746 C  -608120955
3707  form    A  -15228 B  698359410 C  404828523
4890  form    A  13005 B  698360544 C  -443580057
18576  form    A  495 B  698376636 C  -302393871
25559  form    A  -11943 B  698353794 C  680374620
160443  form    A  -10404 B  698371866 C  174481695
268519  form    A  -4059 B  698373468 C  309413907
432575  form    A  -3447 B  698374458 C  264060324
435051  form    A  -1089 B  698375754 C  420265260
472621  form    A  -225 B  698376726 C  525591180
3861006  form    A  123456789 B  493827156 C  -493827165
=========================================

  smallest positive  495 line number  18576

 A  495 B  698376636 C  -302393871

  biggest negative  -225 line number  472621

 A  -225 B  698376726 C  525591180

jagy@phobeusjunior:~$ 
jagy@phobeusjunior:~$ date
Sat Jul 13 22:13:41 PDT 2013
jagy@phobeusjunior:~$ 

============
Here are pages 99 and 111 from Dickson's Intro book:

============
I also put in some custom commands, here are the five smallest positive (primitively represented) values and the five smallest negative (in absolute value). I also told it to show the first 20 rows and the values of $\delta$ which show how to calculate the next "right neighboring" form, given $\langle a,b,c \rangle$ the new form is $ \langle c, -b + 2 c \delta, a - b \delta + c \delta^2  \rangle .$
==================
revised output
jagy@phobeusjunior:~$ 
jagy@phobeusjunior:~$ ./indef_Binary
Input three coefficients a b c for indef f(x,y)= a x^2 + b x y + c y^2 
 123456789  0  -987654321  

123456789  b   0  c  -987654321
 A  -987654321 B  0 C  123456789   DELTA    2
 A  123456789 B  493827156 C  -493827165   DELTA    -1


 continue? 
1

Sun Jul 14 10:15:21 PDT 2013
0  form    A  123456789 B  493827156 C  -493827165   DELTA    -1
1  form    A  -493827165 B  493827174 C  123456780   DELTA    4
2  form    A  123456780 B  493827066 C  -493827381   DELTA    -1
3  form    A  -493827381 B  493827696 C  123456465   DELTA    4
4  form    A  123456465 B  493824024 C  -493834725   DELTA    -1
5  form    A  -493834725 B  493845426 C  123445764   DELTA    4
6  form    A  123445764 B  493720686 C  -494084205   DELTA    -1
7  form    A  -494084205 B  494447724 C  123082245   DELTA    4
8  form    A  123082245 B  490210236 C  -502559181   DELTA    -1
9  form    A  -502559181 B  514908126 C  110733300   DELTA    5
10  form    A  110733300 B  592424874 C  -308767311   DELTA    -2
11  form    A  -308767311 B  642644370 C  60513804   DELTA    11
12  form    A  60513804 B  688659318 C  -55685097   DELTA    -12
13  form    A  -55685097 B  647783010 C  305771652   DELTA    2
14  form    A  305771652 B  575303598 C  -128164509   DELTA    -4
15  form    A  -128164509 B  450012474 C  556353900   DELTA    1
16  form    A  556353900 B  662695326 C  -21823083   DELTA    -31
17  form    A  -21823083 B  690335820 C  127926243   DELTA    5
18  form    A  127926243 B  588926610 C  -275346108   DELTA    -2
19  form    A  -275346108 B  512457822 C  204395031   DELTA    2
20  form    A  204395031 B  305122302 C  -482681628   DELTA    -1
18576  form    A  495 B  698376636 C  -302393871   DELTA    -2
47864  form    A  1395 B  698374404 C  -666001467   DELTA    -1
435051  form    A  -1089 B  698375754 C  420265260   DELTA    1
472621  form    A  -225 B  698376726 C  525591180   DELTA    1
719320  form    A  1053 B  698375916 C  -380912085   DELTA    -1
722818  form    A  1845 B  698374206 C  -541035828   DELTA    -1
796445  form    A  -729 B  698376906 C  76000140   DELTA    9
814403  form    A  -900 B  698375574 C  578358531   DELTA    1
1319754  form    A  621 B  698376456 C  -342252585   DELTA    -2
1625099  form    A  -1521 B  698375466 C  367018380   DELTA    1
1759361  form    A  -900 B  698376726 C  131397795   DELTA    5
2101645  form    A  -900 B  698376474 C  229170519   DELTA    3
2235907  form    A  -1521 B  698374044 C  693477585   DELTA    1
2541252  form    A  621 B  698376744 C  -180310185   DELTA    -3
3046603  form    A  -900 B  698375826 C  480585933   DELTA    1
3064561  form    A  -729 B  698376888 C  84622077   DELTA    8
3138188  form    A  1845 B  698375664 C  -265092561   DELTA    -2
3141686  form    A  1053 B  698375934 C  -374943060   DELTA    -1
3388385  form    A  -225 B  698376924 C  218305377   DELTA    3
3425955  form    A  -1089 B  698375646 C  454895460   DELTA    1
3813142  form    A  1395 B  698374926 C  -535337820   DELTA    -1
3842430  form    A  495 B  698376744 C  -226207323   DELTA    -3
3861006  form    A  123456789 B  493827156 C  -493827165   DELTA    -1
=========================================

Sun Jul 14 10:16:20 PDT 2013
  smallest positive  495 line number  18576

 A  495 B  698376636 C  -302393871   DELTA    -2

  biggest negative  -225 line number  472621

 A  -225 B  698376726 C  525591180   DELTA    1


SMALL ABSOLUTE VALUES

-1521
-1089
-900
-729
-225
495
621
1053
1395
1845

Sun Jul 14 10:16:20 PDT 2013
jagy@phobeusjunior:~$ 

=====================