Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Suppose I know the value of $n$ (where $n = pq$), and I also know $k = p-q$. How can I efficiently factor $n$?

Note that I don't know $p$ or $q$.

EDIT: Thank you for your answers. I understand that I could use basic algebra but would it be efficient to use that if $n$ was large? For example, if $n = 59305397$?

share|improve this question
    
$\rm n=pq=(q+k)q$ yields $\rm q^2+kq-n=0$, which is a quadratic equation. –  anon Mar 5 '13 at 4:33
    
Are you computing by hand? Or by computer? Do you really mean numbers as small as 8 digits? –  Hurkyl Mar 5 '13 at 6:04
    
I am am computing using a standard scientific calculator, not a computer (or writing a program or anything of that sort). –  ChromoZoneX Mar 5 '13 at 6:11

4 Answers 4

up vote 5 down vote accepted

You have a system of two equations in two unknowns; you can appeal to high school algebra!

share|improve this answer

We assume that $p$ and $q$ are huge.

Note that $(p+q)^2=(p-q)^2+4pq$. We know $p-q$ and $pq$, so can compute $(p+q)^2$ cheaply. Now we can compute $p+q$ cheaply, by an adaptation of Newton's Method.

We now know $p-q$ and $p+q$. Calculate $\frac{1}{2}\left((p-q)+(p+q)\right)$.

share|improve this answer

Hint $\ $ Since we have been given both the $\rm\color{#C00}{sum}$ and $\rm\color{#0A0}{product}$ of $\rm\,p\,$ and $\rm\,-q,\,$ we know the coefficients of the quadratic polynomial having $\rm\,p\,$ and $\rm\,-q\,$ as roots, namely

$$\rm (x-p)(x+q)\, =\, x^2 - (\color{#C00}{p\!-\!q})\, x \color{#0A0}{-pq}\ =\ x^2 - k\, x -n $$

Therefore, solving $\rm\ x^2 - k\, x -n\, =\, 0\ $ yields the roots $\rm\:p\:$ and $\rm\:-q.$

share|improve this answer

Note that $p=k+q$, so $n=q(k+q)$ or $q^2+kq-n=0$. This is a quadratic in $q$.

share|improve this answer

Your Answer

 
discard

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.