The document discusses integer arithmetic, focusing on binary operations such as addition, subtraction, and multiplication, while explaining the concept of division and its restrictions. It introduces the Euclidean algorithm for finding the greatest common divisor (gcd) of two integers, along with the extended Euclidean algorithm for finding integer solutions to linear Diophantine equations. Examples are provided to illustrate the application of these algorithms in calculating gcd and solving equations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views35 pages
Mod1 crypto
The document discusses integer arithmetic, focusing on binary operations such as addition, subtraction, and multiplication, while explaining the concept of division and its restrictions. It introduces the Euclidean algorithm for finding the greatest common divisor (gcd) of two integers, along with the extended Euclidean algorithm for finding integer solutions to linear Diophantine equations. Examples are provided to illustrate the application of these algorithms in calculating gcd and solving equations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 35
Integer Arithmetic
In integer arithmetic, we use a set and a few operations
by Z, contains all integral numbers
(with no fraction) from negative infinity to positive infinity
-2,-1,0,1,2,...
binary operation takes two inputs and creates one output
Three common binary operations defined for integers are
addition, subtraction, and multiplicationsee eae
Each of these operations takes two inputs (a and b) and creates
one output (c)
The two inputs come from the set of integers: the Output goes
TORR em re ee
division does not fit in this category because, it produces two
outputs instead of onesee
In integer arithmetic, if we divide a by n, we can get q
ais called the CMGI Te
CAR eme (eld
Pm me A CLol eae LAL |
r, the remainder. We can call itInteger Arithmetic
e Incase ofa positive a, we need to move q x n units to the right
EU Re MMM RUT em cre to)
Eg: 255 = 23x 11+2
Case of I 1
positive aInteger Arithmetic
e While using division we impose two restrictions
e First, the divisor must be a positive integer (n > 0)
e Second, the remainder must be a nonnegative integer
(r > 0)Tee
e Incase of a negative a, we need to move (q-l) x n units to the left
and then move r units in the opposite direction
e In both cases the value of r is positive
=e -255=-23x11+-2 => -255=-24x11+9
Decrement q by 1 and add the value of n to r to make it positive
Case of eo
positive a
eee q a
Case of
boy
negative a
(q-Wn a qnsees
If a is not zero and we let r= 0 in the division relation, we get
a=qxn-
n divides a (or n is a divisor of a) or a is divisible by n
a|1, then a= +1 or -1
2: if alb and bia, then a = +b or -b
3: if alb and bic, thenajc Eg: 3] 15. and 15] 45 => 3 | 45
4: if alb and ajc, then a|(m x b+ n x c), where m and n are arbitrary
integers. Eg: 3| 15 and 3| 9 => 3| (15x 2 +9 x 4) => 3] 66TCU
e A positive integer can have more than one divisor
e Eg: 32 has six divisors: 1,2, 4, 8, 16, and 32
e Fact 1: The integer 1 has only one divisor, itself.
Cig nese Um ie mre Ta (rem Cole mm mie BCLs
e Eg: common divisors of 12 and 140 are 1, 2, and 4. However, the
greatest common divisor is 4Euclidean Algorithm
Euclidean Algorithm Ginding the greatest common divisor (ged) of two positive integers by listing
all common divisors is not practical when the two integers are large. Fortunately, more than 2000 years
ago a mathematician nanfed Euclid developed an algorithm that can find the greatest common divisor
of two positive integers. The Euclidean algorithm is based on the following two facts
Fact 1: ged (a, 0)=a
Fact 2: ged (a, b) = ged (6, 7), where r is the remainder of dividing a by b
The first fact tells us that if the second integer is 0, the greatest common divisor is the first one. The
second fact allows us to change the value of a, b until b becomes 0. For example, to calculate the ged
(36, 10), we can use the second fact several times and the first fact once, as shown below.
‘ged (36, 10) = ged (I zed (6,4) = ged (4,2) = ged (2
In other words, gcd (36, 10) = 2, ged (10, 6) = 2, and so on. This means that instead of calculating
aed (36, 10), we can find ged (2, 0). Figure 2.7 shows how we use the above two facts to calculate god
‘a, b).HS ayy bf (mnitialization)
while (x, > 0)
3 : qen/n
rern-aX nm
no )
ged. =n ged (a DO
a. Process b. Algorithm
2.7. Euclidean algorithm
We use two variables, r; and ry, to hold the changing values during the process of reduction. They are
initialized to a and b. In each step, we calculate the remainder of r; divided by rand store the result ir
the variable r. We then replace r; by ry and rz by r. The steps are continued until ry becomes 0. At this
moment, we stop. The ged (a, 8) is 7.
When ged (a, 6) = 1, we say that a and b are relatively prime.Euclidean Algorithm
Example 2. ind the greatest common divisor of 2740 and 1760.
Solution We apply the above procedure using a table. We initialize r; to 2740 and r2 to 1760. We
have also shown the value of g in each step. We have ged (2740, 1760) = 20.Euclidean Algorithm
Example 2.8 Find the greatest common divisor of 25 and 60. J
Solution We chose this particular example to show that it does not matter if the first number is
smaller than the second number, We immediately get our correct ordering. We have ged (25, 65) =5.
qo * r
0. 625 6 25
2 0 2% ' 10
2 3 wo 5
2 10 5 0
Ls A oe |Extended Euclidean Algorithm
The Extended Euclidean Algorithm Given two integers a and b, we often need to find other
two integers, sand 7, such that
sXat1x b= ged (a,b)
The extended Euclidean algorithmy can calculate the ged (a, 6) and at the same time calculate the
value of s and 1,
extended Euclidean algorithm uses the same number of steps as the Euclidean
algorithm. However, in each step, we use three sets of calculations and exchanges instead of one. The
algorithm uses three sets of variables, r’s, s’s, and 1's. In each step, r,, 72, and r have the same values in
the Euclidean algorithm. The variables r; and rz are initialized to the values of a and b, respectively. The
variables s; and s2 are initialized to | and 0, respectively. The variables f, and f are initialized to 0 and
1, respectively. The calculations of r, s, and / are similar, with one warning. Although r is the remainder
of dividing r; by rz, there is no such relationship between the Sther two sets. There is only one quotient,
4. which is calculated as r;/ r2 and used for the other two calculations.
ged (a. b=r
pagExtended Euclidean Algorithm
me
li 62. 03
t, — 0; t2 1;
while (r, > 0)
{
qer sx:
ees)
Updating 3’
ae, (Updating 3’ s)
ses, +
(Updating s’s
| es ee = al
t et + qx tyr
> 7 (Updating t's)
|) tet tee
}
ged (a e Ee teEuclidean Algorithm
Example 2.8 Find the greatest common divisor of 25 and 60. J
Solution We chose this particular example to show that it does not matter if the first number is
smaller than the second number, We immediately get our correct ordering. We have ged (25, 65) =5.
qo * r
0. 625 6 25
2 0 2% ' 10
2 3 wo 5
2 10 5 0
Ls A oe |Extended Euclidean Algorithm
me
li 62. 03
t, — 0; t2 1;
while (r, > 0)
{
qer sx:
ees)
Updating 3’
ae, (Updating 3’ s)
ses, +
(Updating s’s
| es ee = al
t et + qx tyr
> 7 (Updating t's)
|) tet tee
}
ged (a e Ee teExtended Euclidean Algorithm
Example 2.9. Given a= 164 and b = 28, find gcd (a, b) and the values of s and t.
ae
Solution
PEM —qXrq S=5)-GXsq 1=h-GXh
We use a table to follow the algorithm,
We get ged (161, 28) = 7, s =—I and ¢= 6. The answers can be tested because we have
C1) x 161 +6x28=7Extended Euclidean Algorithm
Example 2.9. Given a= 164 and b = 28, find gcd (a, b) and the values of s and t.
ae
Solution
PEM —qXrq S=5)-GXsq 1=h-GXh
We use a table to follow the algorithm,
We get ged (161, 28) = 7, s =—I and ¢= 6. The answers can be tested because we have
C1) x 161 +6x28=7Extended Euclidean Algorithm
Example 2.10 _ Given a= 17 and b = 0, find gcd (a, b) and the values of s and ¢.
Solution We use a table to follow the algorithm.
Gon) ntt-a00a..| 17 [asi Ea ee
17 io oi.
Note that we need no calculation for q, r, and s. The first value of r; meets our termination condition.
We get ged (17, 0) = 17, s= 1, and ¢= 0. This indicates why we should initialize sy to 1 and f, to 0. The
answers can be tested as shown below:
(1x 17) + x0) =17
Example 2.11 _ Given a= 0 and b = 45, find gcd (a, b) and the values of s and t.
Solution We use a table to follow the algorithm.
[=[+[s]s[* [ale]?
a} o|{1]o0)]1 [0110
oto" at 11
We get ged (0, 45) = 45, s = 0, and = 1. This indicates why we should initialize sto 0 and f 101
The answer can be tested as shown below:
(x0) +(1 x 45) = 45Linear Diophantine Equations
e A Diophantine equation is a polynomial equation,
usually in two or more unknowns, such that only the
integral solutions are required
e An Integral solution is a solution such that all the
unknown variables take only integer values
e Extended Euclidean Algorithm can be used to
find the solutions to the linear Diophantine
equations of two variables, an equation of type
ax + by =c C