3

Suppose that the general equation $f(x,y) = x + y + Sqrt[x*y]$ is to be used to find the values of $x$ and $y$ such that $f(x,y)$ is an integer, ideally using IntegerQ[n + m + Sqrt[n*m]].

The question is: What is an efficient method to select integers $n$ and $m$ to produce values of IntegerQ[n + m + Sqrt[n*m]] ?

Known examples: $(n,m) \in \{(0,1), (1,1), (1,4), (5,20), \cdots \}$

Artes
  • 57,212
  • 12
  • 157
  • 245
Leucippus
  • 365
  • 2
  • 4
  • 14

3 Answers3

7

Finding distinct integers that satisfy function is equivalent to finding integers such that $x \times y = n^2$ for some integer $n$ In the following I only find $(m,n): m<n $ but obviously $(n,m)$ also satisfies. For "small numbers":

func[n_] := Module[{su = Subsets[Range[n], {2}], d},
  d = Mod[Length@*Divisors /@ Times @@@ su, 2];
  Pick[su, d, 1]]

enter image description here

enter image description here

Visualizing real solutions:

pf[n_] := 
 Plot3D[x + y + Sqrt[x y], {x, 0, n}, {y, 0, n }, 
  MeshFunctions -> {#3 &}, Mesh -> {Range[3 n]}, MeshStyle -> Red, 
  PlotStyle -> White]
Row[{pf[10], pf[30]}]

enter image description here

And showing integer pairs with real solutions:

pfm[n_, s_] := 
 Plot3D[x + y + Sqrt[x y], {x, 0, n}, {y, 0, n }, 
  MeshFunctions -> {#3 &}, Mesh -> {Range[1, 3 n, s]}, 
  MeshStyle -> Red, PlotStyle -> White]
f[x_, y_] := x + y + Sqrt[x y];
pts[n_] := 
 Graphics3D[{PointSize[0.02], Point[{##, f[##]} & @@@ func[n]]}]
Show[pfm[30, 1], pts[30]]

enter image description here

enter image description here

enter image description here

ubpdqn
  • 60,617
  • 3
  • 59
  • 148
4
f[x_, y_] := x + y + Sqrt[x*y]

max = 500;

(soln1 =
    Select[
     Table[{x, y}, {x, 0, max}, {y, 0, max}] //
      Flatten[#, 1] &,
     IntegerQ[Sqrt[Times @@ #]] &];) //
 RepeatedTiming

*  {2.45, Null}  *)

Length[soln1]

(*  2959  *)

Verifying that when f is applied to each pair that the result is an integer

And @@ IntegerQ@*f @@@ soln1

(*  True  *)

Second method

(soln2 =
    Table[
      If[IntegerQ[Sqrt[x*y]], {x, y}, Nothing], {x, 0, max}, {y, 0, max}] //
         Flatten[#, 1] &;) //
 RepeatedTiming

(*  {2.35, Null}  *)

Verifying that the two results are identical

soln1 === soln2

(*  True  *)

The n (2959) results can be reduced to (n+1)/2 (1480) unique results since x and y are interchangeable.

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
3

As mentioned previously by others, you need integer pairs $\{x,y\}$ such that $x*y=z^2$. I think the fastest and simplest code is to find pairs with $x\le y$ via DivisorPairs[z^2] defined below.

DivisorPairs[n_] := Thread[{#,Reverse[#]}][[;; Ceiling[Length[#]/2]]]&[Divisors[n]]

For example,

DivisorPairs[10^2]

{{1, 100}, {2, 50}, {4, 25}, {5, 20}, {10, 10}}

The following returns integers $\{x,y\}$ such that $x+y+\sqrt{x*y}$ is an integer, up to an arbitrary maximum $z_{max}^2=x*y$.

With[{zmax = 12}, Flatten[Table[DivisorPairs[z^2], {z, 1, zmax}], 1]]

{{1, 1}, {1, 4}, {2, 2}, {1, 9}, {3, 3}, {1, 16}, {2, 8}, {4, 4}, {1, 25}, {5, 5}, {1, 36}, {2, 18}, {3, 12}, {4, 9}, {6, 6}, {1, 49}, {7, 7}, {1, 64}, {2, 32}, {4, 16}, {8, 8}, {1, 81}, {3, 27}, {9, 9}, {1, 100}, {2, 50}, {4, 25}, {5, 20}, {10, 10}, {1, 121}, {11, 11}, {1, 144}, {2, 72}, {3, 48}, {4, 36}, {6, 24}, {8, 18}, {9, 16}, {12, 12}}

Further processing could eliminate non-distinct pairs, or include trivial pairs $\{0,y\}$.

KennyColnago
  • 15,209
  • 26
  • 62