0
$\begingroup$

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...

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

3 Answers 3

3
$\begingroup$

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.

$\endgroup$
8
  • $\begingroup$ I see that now! $\endgroup$
    – Cato
    Sep 23, 2016 at 10:41
  • $\begingroup$ 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? $\endgroup$
    – Newskooler
    Sep 23, 2016 at 11:31
  • $\begingroup$ 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. $\endgroup$ Sep 23, 2016 at 11:46
  • $\begingroup$ @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?) $\endgroup$
    – Cato
    Sep 23, 2016 at 12:01
  • 1
    $\begingroup$ If you will look more carefully @Zestylemonzi you will see I did not forget anything. $\endgroup$ Sep 23, 2016 at 20:45
2
$\begingroup$

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\}$

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

$\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}

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

Not the answer you're looking for? Browse other questions tagged .