# Find all the integers that satisfy for $x$ [closed]

I was asked the following question during a job interview.

$x, a$ & $b$ are integers and we have: $$a = x+1$$ $$b = x^2+1$$

Find all the $x$ values such that when $b$ is divided by $a$ there is no remainder; i.e. the answer is an integer too.

My approach was the following: $$b = x^2-1+2$$ $$= (x-1)(x+1)+2$$ this leaves us with: $$\frac{b}{a} = \frac{(x-1)(x+1)+2}{x+1}$$ From here on I have lost my way...

• @IttayWeiss I have just edited my question. Sep 23, 2016 at 10:02
• What are your a and b? Sep 23, 2016 at 10:03
• @mathlover a and b are both integers as defined in the question, since x is an integer. Sep 23, 2016 at 10:05

Continuing your work: $b/a = x-1 + \frac{2}{x+1}$ and since $x-1$ is an integer, the quantity $b/a$ is an integer if, and only if, $2/(x+1)$ is an integer. That happens precisely when $x+1\in\{-2,-1,1,2\}$ and I'm sure you can finish the argument.

• I see that now!
– Cato
Sep 23, 2016 at 10:41
• I agree with 1 and -2, however how can -1, and 2 give the correct answer? IF we put -1, we get to divide by 0. If we input 2, we get 1.66667 (not an integer). Am I missing something or has the question been phrased wrongly? Sep 23, 2016 at 11:31
• Ittay has shown that if $x$ is a solution to your problem then it must belong to $A:=\{-2,-1,1,2\}$. This doesn't show that all the elements in $A$ are solutions, you need to check to see if they are. i.e Ittay's solution has whittled down the possible values of $x$ and now you just need to check which ones work. Sep 23, 2016 at 11:46
• @Newskooler - I didn't read it carefully, but it is all 100% clear and correct of course, x+1 has to belong to that set of numbers, so therefore x belongs to (what set of numbers?)
– Cato
Sep 23, 2016 at 12:01
• If you will look more carefully @Zestylemonzi you will see I did not forget anything. Sep 23, 2016 at 20:45

Let $$\frac{x^2 + 1}{x + 1} = k, \quad \text{or} \quad x^2 - kx + 1 - k = 0.$$ Solutions of this equation are $$x_{1,2} = \frac{k\pm\sqrt{k^2+4k-4}}{2}.$$ Now we want $k\in\mathbb{N}$ or $k^2 + 4k - 4 = m^2$ for some integer $m$. This leads us to $$(k+2)^2 - 8 = m^2$$ or $$(k+2)^2 - m^2 = (k+2 + m)(k+2-m) = 8.$$ $8$ has only two divisors more than $2$: $4$ and $8$, thus our four cases are $$\begin{cases} k + 2 + m = 8\\ k + 2 - m = 1 \end{cases}, \quad \begin{cases} k + 2 + m = 4\\ k + 2 - m = 2 \end{cases}.$$ $$\begin{cases} k + 2 + m = -8\\ k + 2 - m = -1 \end{cases}, \quad \begin{cases} k + 2 + m = -4\\ k + 2 - m = -2 \end{cases}.$$ Only second and fourth cases gives us integer values of $k = 1$ and $k = -5$, so for $x$ we have $$x_{1,2} = \frac{1\pm\sqrt{1^2+4-4}}{2}, \quad x_{3,4} = \frac{-5\pm\sqrt{5^2-4\cdot 5-4}}{2}$$ which implies $x \in \{-3,-2,0,1\}$

• -3 gives 10 / -2 = -5 as far as I could see
– Cato
Sep 23, 2016 at 10:32
• could you please show how you got from the first line of equation to the second ($x_1,_2$) Sep 23, 2016 at 10:34
• @AndrewDeighton thanks for comment, I've considered only $k>0$ and that was mistake, of course Sep 23, 2016 at 10:40
• @Newskooler see en.wikipedia.org/wiki/Discriminant#Quadratic_formula Sep 23, 2016 at 10:42
• @AntonGrudkin math is rusty, but it all comes flowing back now. Thanks! Sep 23, 2016 at 11:17

$\frac{x^2 + 1}{x+1} = \frac{x^2 + x - x + 1}{x+1} = x + \frac{1- x}{x+1}$

then (x-1) / (x + 1) would need to be an integer, to combine with x an integer

which it is for x=0,x = 1, then x = 2 you've got 1/3 ,and you can see for larger x, it will just go 2/4,3/5 and never be an integer again for any further x+1

-1 gives infinity, that will never work, -1 can be seen to not work in the equations, -2 gives 3/-1 - so it seems to work, then -3 gives -4/-2 - works, -5/-3, -6/-4,-7/-5 - will never work again for any x-1

so I get {0, 1,-2,-3}

• I like this brute-force approach, as it provides some intuition on the numbers past 2 and -4. Nice one! Sep 23, 2016 at 11:44