Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given the equation

$f(k) = 4-7k $

what is the easiest way to find which integer values of $k$ makes $f(k)$ a perfect square $(-3, -11, ...)$

(I hope for something better than just testing values of $k$)

share|cite|improve this question
Take all perfect squares and apply $f^{-1}$? Your $f$ is bijective so this will work for any perfefct square. If you want integer solutions of $k$, this will also narrow down the needed "tests". – AlexR Dec 6 '13 at 12:35
Ah yes, i need integer solutions.. should have specified that. sorry. – ChessMetrics Dec 6 '13 at 12:36
$k=\frac{-x^2+4}{7}$ where $x\in\mathbb{N}$ – Riccardo.Alestra Dec 6 '13 at 12:37
@Riccardo.Alestra note that in general $7 \not | -x^2 + 4$ and thus $f^{-1}(x^2)$ might not be in $\mathbb Z$. – AlexR Dec 6 '13 at 12:38
I am only interested in integer values of k. – ChessMetrics Dec 6 '13 at 12:42
up vote 1 down vote accepted

Let's reduce the possibilities first by working modulo 7. The equation $x^2 = 4 - 7k$ implies that $\overline x^2 = 4 \in \mathbb{Z}/7\mathbb{Z}$. A quick check shows that $\overline 2$ and $\overline 5$ are the only numbers in that ring that square to 2. So we must have $x \equiv 2$ or $x \equiv 5$ modulo 7.

The second step is a trick. We are only interested in $x^2$, so we do not care if we use $x$ or $-x$. If $x \equiv 5$ modulo 7 we can replace $x$ by $-x$ and then obtain $x \equiv 2$ modulo 7.

So we know that there is an integer $m$ such that $x = 7m +2$. Let's see if all $m$ work.

\begin{align*} x^2 &= 4 - 7k\\ (7m+2)^2 &= 4 - 7k\\ 49m^2 + 14m + 4 &= 4 - 7k\\ 49m^2 + 14m &= -7k\\ -(7m^2 + 2m) &= k \end{align*}

So not only we must have $x = 7m +2$, also all integer values for $m$ work. The above values for $k$ are your final answer.

share|cite|improve this answer

Consider $f(k)=j^2$ whenever any value of $k$ gives a perfect square.

Now, $j^2-4=-7k$


Since, $gcd(7,k)=1$

So,whenever, $7|(j-2)$ or $7|(j+2)$, we get a solution.

share|cite|improve this answer
This was very nice...Thanks – ChessMetrics Dec 6 '13 at 12:51
@ChessMetrics.Most welcome! – Hawk Dec 6 '13 at 12:52

As mentioned in the comments your function is bijective, so every square $x^2$ where $x\in \mathbb{Z}$ has exactly one inverse image given by $f^{-1}(x^2)=\frac{4-x^2}{7}$. Now you just need to work out for which values of $x$ $f^{-1}(x^2)$ is an integer, or for which values of $x$, $x^2\equiv4$ mod $7$. By checking all residues mod $7$ we conclude that $x$ has to be congruent to $2$ or $5$ mod $7$.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.