Gaussian integer factorization calculator

The Gaussian integers are complex numbers of the form a + bi, where both a and b are integer numbers and i is the square root of -1.

This applet is able to factor a Gaussian integer as a product of Gaussian primes. This decomposition is unique, if we do not consider the order of the factors.

Factoring Gaussian integers

An important concept needed for Gaussian integer factorization is the norm. This is defined as: N(a+bi) = a2 + b2.

The product of the norm of two Gaussian integers is equal to the norm of the products of these numbers as can be easily seen as follows:

N(a+bi) N(c+di) = (a2 + b2) (c2 + d2) = (ac)2 + (bd)2 + (ad)2 + (bc)2 = (ac)2 - 2abcd + (bd)2 + (ad)2 + 2abcd + (bc)2 = (ac-bd)2 + (ad+bc)2 = N((ac-bd)+(ad+bc)i) = N(a(c+di) + b(-d+ci)) = N(a(c+di) + bi(c+di)) = N((a+bi) (c+di))

In the next to last expression we used the fact that i2 = -1.

This means that the first step when trying to factor a Gaussian integer is to factor its norm into integer primes, so we get the norm of the factors of the original number.

The second step is to obtain the factors from the norm of the factor.

There are three cases:

  1. The prime factor p of the norm is 2: This means that the factor of the Gaussian integer is 1+i or 1-i.
  2. The prime factor p of the norm is multiple of 4 plus 3: this value cannot be expressed as a sum of two squares, so p is not a norm, but p2 is. Since p2 = p2 + 02, and there is no prime norm that divides p2, the number p + 0i is a Gaussian prime, and the repeated factor p must be discarded.
  3. The prime factor p of the norm is multiple of 4 plus 1: this number can be expressed as a sum of two squares, by using the methods explained in the sum of squares page. If p = m2 + n2, then you can check whether m + ni or mni are divisors of the original Gaussian number.

Why does a number which is multiple of 4 plus 3 cannot be expressed as a sum of two squares? This is because the square of an even number is multiple of 4, and the square of an odd number is multiple of 4 plus 1. So we get:

So under no circumstances a sum of two squares can be multiple of 4 plus 3.

Of course the first step is a lot more difficult than the second step. This is because we do not know efficient integer factorization for huge numbers.

Example: factor the Gaussian integer 440 − 55i

The norm is 4402 + 552 = 196625 = 5 × 5 × 5 × 11 × 11 × 13

Both 5 and 13 are multiples of 4 plus 1 while 11 is a multiple of 4 plus 3. We can use the fact the 5 = 22 + 12 and 13 = 32 + 22

Since 11 is a Gaussian prime, we can divide the original number by 11 and get 44 − 5i.

For the three factors of the norm equal to 5, we have to divide the result of the previous step 44 − 5i by 2−i or 2+i. So we get: 44 − 5i = (2+i)2 × (2-i) × (3 − 2i)

For the factor 13 we have to divide the result of the previous step 3 − 2i by 3 + 2i or 3 − 2i. Of course only 3 − 2i divides 3 − 2i.

The complete factorization is: 440 − 55i = 11 × (2 + i)2 × (2 − i) × (3 − 2i).


In order to enter the imaginary part of a Gaussian integer you can use the symbol i, as in the next example: 3+4i.

You can also enter expressions that use the following operators, functions and parentheses:

You can use the prefix 0x for hexadecimal numbers, for example 0x38 is equal to 56.

Source code

You can download the source of the current program and the old sum polynomial factorization applet from GitHub. Notice that the source code is in C language and you need the Emscripten environment in order to generate Javascript.

Written by Dario Alpern. Last updated 4 August 2016.

If you find any error or you have a comment, please fill in the form.