<s>[INST] How to decide this function takes integer values? I am working a combinatorial question. I need to decide when  the following function
$$\frac{m(7m^2 - 22m +7)}{  \sqrt{ (m^2- 2m + 9)(9m^2 - 2m +1) } } $$takes integer values with following 
assumption: 1) m takes all positive integer values; 2) $(m^2- 2m + 9)(9m^2 - 2m +1)$ is a perfect square (= $n^2$ for some integer $n$). Limited computation for $m < 20000$ shows $m = 1, 5$. 
Many thanks, 
Jianmin     
 [/INST] An elementary approach is enough here. If the given ratio is an integer, then any prime $p$ which divides $m^2 -2m+9$ divides either $m$ or $7m^2-22m+7$. If $p$ divides $m$ then clearly $p =3$. If $p$ divides $7m^2-22m+7$ then $p$ divides $$[7m^2-14m+63 - (7m^2-22m+7)] = 8m+56. $$
Hence either $p=2$ or $p$ divides $m+7.$ In the second case,
$p$ divides $$(m^2-2m+9) -(m+7) = 
m^2-3m+2 = (m-1)(m-2).$$ Now $p$ divides $8$ if $m \equiv 1$ (mod p) and
$p$ divides $9$ if $m \equiv 2$ (mod p). Hence $(m-1)^2 +8$ has the form
$2^a 3^b$. The greatest common divisor of $7m^2 -22m+7$
and $9m^2-2m+1$ is also very restricted. If $p$ is an odd prime which divides
both $7m^2-22m +7$ and $9m^2-2m+1$, then (subtracting the first from the second and dividing by $2$), $p$ divides $m^2 +10m-3$. Then (subtracting the first equation from $7$ times the new equation), $p$ divides $92m-28  = 4(23m-7)$ and hence $p$ divides $7m^2 +m = 7m^2-22m +7 + (23m-7).$ Since $p$ does not divide $m$, $p$ divides $7m+1$, and thus divides $(23m-7)-3(7m+1) = 2(m-5).$ But now  $p$ also divides $7(m-5) + 36$, so $p$ divides $36$ and $p=3$.
Hence we see that $m^2 -2m+9$  has the form $2^a 3^b$ and $9m^2 - 2m+1$ has the
form $2^e 3^f$ for integers $a,b,e,f$. But now notice that the greatest common
divisor $d$ of $m^2 -2m+9$ and  $9m^2 - 2m+1$ divides $16m-80$, which is the latter equation minus 9 times the former. Also, $16$ does not divide $d$, since` $(m-1)^2 +8$ is not divisible by 16
(and neither is $8m^2 +(m-1)^2$). If $h$ is the odd part of $d$, then $m \equiv 5$ (mod h), and $h$ divides $24$. Hence $d$ divides $24$. If $m$ is divisible by $3$,  then $9m^2 - 2m+1$ must be a power of $2$, but is not divisible by $16$, yielding $m=0$ under current assumptions. Hence we may suppose that $m$ is not divisible by $3$. If $9$ divides $m^2-2m +9$, then $ m \equiv 2 $ (mod 9) so $9m^2 - 2m+1 \in \{3,12,24\}$, a contradiction. Hence $m^2-2m +9  = 24$  and $m= 5$
or  $m^2-2m +9  = 8$  and $m= 1$ are the only remaining possibilities (for positive $m$ not divisible by 3, as we are currently assuming). Thus $m=1 $ and $m=5$ are the only positive integers which yield an integral value. (Later remark: Note that the additional solution $m=-1$ mentioned in the comment of Noam Elkies corresponds to the case $9m^2 - 2m+1 = 12 = m^2 -2m +9$, which does not occur for  positive $m$). 
</s>