The Euclidean algorithm for the Gaussian integers.
The Gaussian integers define a grid on the complex plane.
The multiples of a complex number like (5+2 i)define a grid, too:
The diagonal of a cell of the lattice of multiples of a Gaussian integer n is
|n|. This means that all Gaussian integers are within
of a multiple of n. Since
<1, any Gaussian integer can be expressed in the form: n=q m+r, where q and m are Gaussian integers and r is a remainder with modulus less than m.
The greatest common divisor of two Gaussian integers, gcd(a,b), can be defined as a Gaussian integer d of maximum modulus which divides both a and b. It is not unique because we can multiply by ±1 or ±i to get another Gaussian integer of the same modulus which also divides a and b. Any of these quantities can be considered as the gcd. Since Mathematica defines functions for general arguments the same algorithm will work.
From Koblitz (A Course in Number Theory and Crypthography),we may use the complex gcd algorithm to write certain large primes as a sum of two squares. Suppose a prime p divides
+1. Then we may write p=
+
for some integers c and d. Since
+
=(c+di)(c-di), we only have to find a nontrivial Gaussian integer of p. Then
Since p is prime it must divide one of the factors in the right hand side of the first equality. If p|
+1=(b+i)(b-i), then gcd(p,b+i)will give c+di. If p|
-
+1=((
-1)+bi)((
-1)-bi), then gcd(p,(
-1)+bi)will give c+di.
Example. The prime 12277 divides the second factor in
+1=(
+1)(
-
+1), so we find gcd(12277,(
+1)+20i):
Therefore, 12277 =
+
The native Mathematica algorithm gives another equally correct gcd:
Maximum power of a prime dividing n!
What is the maximum power of a prime p dividing n!? One way to obtain this answer is by using the formula
, where
(n) is the sum of the digits of the base p representation of n. This formula is easily obtained by writing the quotients and remainders when expressing n in base p.
n=p⌊
⌋+
,
⌊
⌋=p⌊
⌋+
,
⌊
⌋=p⌊
⌋+
,
...
⌊
⌋=
,
where n=![]()
+![]()
+...+
p+
. Observe that we readily get the formula by solving for the
in each equation and then adding them all.
| Created by Mathematica (June 3, 2006) |