``G-d created the integers. All else is the work of man.'' - Kronecker.
Number theory is the study of the properties of the integers, specifically integer divisibility. It is a fascinating area is beautiful proofs and surprising results.
We say divides (denoted ) if for some integer . Equivalently, we say that is a divisor of or is a multiple of if .
As a consequence of this definition, the smallest natural divisor of every non-zero integer is 1. In general there is no integer such that .
A prime number is an integer which is only divisible by and itself.
Said another way, if is a prime number, then for integers implies that and .
The fundamental theorem of arithmetic. states is that every integer can be expressed in only one way as the product of primes. is uniquely expressed as , and is uniquely expressed as .
This unique set of numbers multiplying to is called the prime factorization of .
Any number which is not prime is said to be composite.
Not only are there an infinite number of primes (see Euclid's proof), but there are a lot of them. There are roughly primes less than or equal to , i.e. roughly one out of every numbers is prime.
The easiest way to find the prime factorization of an integer is repeated division. Note the that smallest prime factor is must at most unless is prime.
Every divisor is the product of some subset of these prime factors. Such subsets can be constructed using backtracking techniques, but we must be careful about duplicate prime factors. For example, the prime factorization of 12 has three terms (2, 2, and 3) but 12 has only 6 divisors (1, 2, 3, 4, 6, 12).
The greatest common divisor, or gcd, the largest divisor shared by a given pair of integers. The reduced form of the fraction comes after we divide both the numerator and denominator by , in this case 12.
Euclid's GCD algorithm rests on two observations. First,
If , then .This should be pretty clear. If divides , then for some integer , and thus . Second,
If for integers and , then .Why? By definition, . Any common divisor of and must rest totally with , because clearly must be divisible by any divisor of .
It can also find integers and such that
/* Find the gcd(p,q) and x,y such that p*x + q*y = gcd(p,q) */ long gcd(long p, long q, long *x, long *y) { long x1,y1; /* previous coefficients */ long g; /* value of gcd(p,q) */ if (q > p) return(gcd(q,p,y,x)); if (q == 0) { *x = 1; *y = 0; return(p); } g = gcd(q, p%q, &x1, &y1); *x = y1; *y = (x1 - floor(p/q)*y1); return(g); }
The least common multiple (lcm), the smallest integer which is divided by both of a given pair of integers. For example, the least common multiple of 24 and 36 is 72.
To compute it, observe that .
Sometimes computing the remainder is more important than a quotient.
What day of the week will your birthday fall on next year? All you need to know is the remainder of the number of days between now and then (either 365 or 366) when dividing by the 7 days of the week. Thus it will fall on this year's day plus one ( ) or two ( ) days, depending upon whether it is affected by a leap year.
The key to such efficient computations is modular arithmetic.
The number we are dividing by is called the modulus, and the remainder left over is called the residue.
What is
?
We can simplify this to
Subtraction s just a special case of addition.
Since multiplication is just repeated addition,
Since exponentiation is just repeated multiplication,
Division proves considerably more complicated to deal with...
What is the last digit of ? We can do this computation by hand. What we really want to know is what is. By doing repeated squaring, and taking the remainder at each step we make progress very quickly:
Congruences are an alternate notation for representing modular arithmetic. We say that if . By definition, if is , then .
It gets us thinking about the set of integers with a given remainder , and gives us equations for representing them.
What integers satisfy the congruence ? The set of solutions is all integers of the form , where is any integer.
What about and ?
Trial and error should convince you that exactly the integers of the form satisfy the first example, while the second has no solutions at all.
Congruences support addition, subtraction, and multiplication, as well as a limited form of division - provided they share the same modulus:
Note that division can be defined as multiplication by an inverse, so is equivalent to . But this inverse does not always exist - try to find a solution to .
We can simplify a congruence to , so we can divide all three terms by a mutually common factor if one exists. Thus implies that .
A linear congruence is an equation of the form . Solving this equation means identifying which values of satisfy it.
Not all such equations have solutions. has a solution if and only if the modulus and the multiplier are relatively prime, i.e., . We may use Euclid's algorithm to find this inverse through the solution to .
In general, there are three cases, depending on the relationship between , , and :
The Chinese remainder theorem gives us a tool for working with systems of congruences over different moduli. Suppose there is exists an integer such that and . Then is uniquely determined if and are relatively prime.
Diophantine equations are formulae in which the variables are restricted to integers. For example, Fermat's last theorem concerned answers to the equation .
The most important class are linear Diophantine equations of the form , where and are the integer variables and , , and are integer constants. These are readily shown to be equivalent to the solving the congruence and hence can be solved using the techniques above.
110702 (Carmichael Numbers) -
Which composite integers always satisfy the equation
110704 (Factovisors) - Does divide ? Does this require large integer arithmetic?
110707 (Marbles) - What is the cheapest way to perfectly store among two types of boxes?
110708 (Repackaging) - Cups of three sizes are sold in certain predefined sets with a given number of each type of cup per package. Can we buy packages so we end up with exactly the same number of all three types of cups?