We know that if $\gcd(a,b)$ is equal to $1,$ then they are relatively prime.

However, I have seen all pairs $(a,b)$ as positive integers. My question is can any pair $(a,b)$ of negative integers be relatively prime?

For example, are $(-1,-1)$ and $(-18,-5)$ relatively prime?

  • 5
    $\begingroup$ Yes and yes and yes. $\endgroup$
    – WhatsUp
    Jul 4, 2020 at 15:31
  • 1
    $\begingroup$ Well, it depends on exactly what you mean. I expect that any mathematician would define $\gcd(a,b)$ to be the greatest integer $d$ which divides both $a$ and $b$, in which case $a, b$ could certainly be negative. But many standard software systems require positivity. I just checked, and Wolfram seems to have no problem with negative arguments, but Excel reported an error. $\endgroup$
    – lulu
    Jul 4, 2020 at 15:34
  • $\begingroup$ If the gcd is equal to 1, not zero. The gcd is uniquely determined modulo units in the underlying ring, here ring of integers and the units there are +1 and -1. $\endgroup$
    – Wuestenfux
    Jul 4, 2020 at 15:37
  • $\begingroup$ @lulu thanks sir, your answer is what i want to ask $\endgroup$ Jul 4, 2020 at 15:37
  • $\begingroup$ For those who are answering, what about pairs like $(+a,-a)$? Does it matter if $a=1$, or $a$ is a prime number, or $a$ is a composite number? $\endgroup$ Jul 4, 2020 at 15:37

2 Answers 2


We may define relatively prime integers as follows.

Two integers are relatively prime if they do not have any common prime factors.

For example $5$ and $-12$ are relatively prime because the only prime factor of $5$ is $5$ which is not a facotor of $-12$ whose prime factors are $2$ and $3$.


Given two integers $a$ and $b,$ we can obtain $\gcd(a, b) = d$ by running the Euclidean Algorithm. Explicitly, there exist integers $q_0$ and $r_0$ such that $a = bq_0 + r_0$ and $0 \leq r_0 \leq |b| - 1.$ Given that $r_0$ is nonzero, there exist integers $q_1$ and $r_1$ such that $b = r_0 q_1 + r_1$ and $0 \leq r_1 \leq r_0 - 1.$ Continuing in this way, there exists an integer $k$ such that $r_k \geq 1$ and $r_{k + 1} = 0$ by the Well-Ordering Principle. One can prove that $r_k = \gcd(a, b).$

Consequently, the greatest common divisor can be defined for any pair of integers $(a, b)$ regardless of their respective signs. We say that two integers $(a, b)$ are relatively prime whenever $\gcd(a, b) = 1,$ so again, this does not depend on the sign of $a$ and $b.$


You must log in to answer this question.

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