cont`d from prime-number slides - Computer Science

advertisement
Intro to Maths for CS:
Numerical Factors
(cont’d from prime-number slides)
Joshua Knowles
School of Computer Science, University of Birmingham
Term 1, 2015-16
(Slides by John Barnden)
Textbook Part
still in Programme F.1, section on Factors and Prime Numbers
Barnden (SoCS)
Intro to Maths for CS: Numerical Factors(contd from prime-number slides)
Term 1, 2014–15
2/9
Highest Common Factors (HCFs) or Greatest Common Divisors(GCDs)
Definition: The HCF (or GCD) of two natural numbers (at least one > 0) is the largest
number that is a factor of them both.
Proposition (“Prime Factor Method” [my name]): The HCF h of two numbers m and
n (both > 0) has the following prime factorization (PF):
The prime factors in it are those that are in BOTH the PF of m AND the PF of n;
and the power to which any prime factor is raised within PF(h) is the MINIMUM of
its power in the PF(m) and its power in PF(n).
(If there are no prime factors in common then the HCF is 1.)
Example:
m = 1800 =
n = 20625 =
h=
Barnden (SoCS)
23 × 32 × 52
31 × 54 × 11
31 × 52
= 75
Intro to Maths for CS: Numerical Factors(contd from prime-number slides)
Term 1, 2014–15
3/9
HCFs, contd
Proposition: The HCF of two numbers m, n where 1 < m ≤ n is the HCF of m and r ,
where r is the remainder from dividing n by m.
Reason: n = km + r , so anything that divides m and r also divides n, and anything
that divides m and n also divides r .
Corollary (“Iterated Remainders Method” [my name]): We can find the HCF of two
numbers greater than 1 by replacing them by their minimum and remainder as
above, and keeping on doing this until one number is 0 (in which case the HCF is
the other number) or 1 (in which case the HCF is 1).
Example:
1800,
20625 (= 1800 × 11 + 825)
1800 (= 825 × 2 + 150),
825
150,
825 (= 150 × 5 + 75)
150,
75
0,
75.
EXERCISE: Try it with 1800 and 20626, and any other pairs of numbers of your choice!
Barnden (SoCS)
Intro to Maths for CS: Numerical Factors(contd from prime-number slides)
Term 1, 2014–15
4/9
HCF of More than Two Numbers
The notion of HCF can be straightforwardly extended to more than two natural numbers
(at least one > 0): it’s the largest number that’s a factor of all of them.
The prime-factor method can easily be extended to finding the HCF of more than two
natural numbers.
Exercise: Make sure you understand what that amounts to in detail, practising on
various cases.
The iterated-remainder method can also easily be extended to finding the HCF of more
than two numbers. At each stage, we still take the smallest of the (non-zero)
numbers, m, and find the remainders of the others on division by m.
Exercise: But when do we stop, and with what result?
Try out a few cases, with three or four numbers each time. Try cases where you
know that the HCF is bigger than 1 and cases where you know the HCF is 1 (but
including cases where a subset of the numbers have an HCF more than 1).
Barnden (SoCS)
Intro to Maths for CS: Numerical Factors(contd from prime-number slides)
Term 1, 2014–15
5/9
Lowest Common Multiples (LCMs)
Definition: The LCM (lowest or least common multiple) of two natural numbers (> 0) is
the smallest number that is a multiple of them both (i.e., of which they are both a
factor).
Proposition (Prime-Factor Method): The LCM h of two numbers m and n has the
following prime factorization (PF):
The prime factors in it are those in the PF of m OR the PF of n;
and the power to which any prime factor is raised within PF(h) is the MAXIMUM
of its power in the PF(m) and its power in PF(n). (If it doesn’t appear in a
factorization, its power is zero there.)
Example:
m = 126 = 2 × 32 × 7 =
n = 375 = 3 × 53 =
l=
Barnden (SoCS)
21 × 32 × 50 × 71
20 × 31 × 53 × 70
21 × 32 × 53 × 71
Intro to Maths for CS: Numerical Factors(contd from prime-number slides)
= 15750
Term 1, 2014–15
6/9
LCM of More than Two Numbers
The notion of LCM can be straightforwardly extended to more than two natural numbers:
it’s the smallest number that’s a multiple of all of them.
The prime-factor method can easily be extended to finding the LCM of more than two
numbers.
Exercise: Make sure you understand what that amounts to in detail, practising on
various cases.
Barnden (SoCS)
Intro to Maths for CS: Numerical Factors(contd from prime-number slides)
Term 1, 2014–15
7/9
Relationship between LCM and HCF of TWO Numbers
Proposition: LCM(m, n) × HCF(m, n) = m × n
Reason: Follows easily from the Propositions about the prime factors in the LCM
and HCF, together with the fact that p a+b = p a p b . EXERCISE: Make the argument
in detail.
Corollary (“Finding LCM via HCF”):
To find LCM(m, n), find HCF(m, n) and then divide that into mn.
Example:
For 126 and 375, the HCF is 3. So the LCM is 126 × 375/3 = 15750.
Caution: It is NOT true that when there are more than two numbers, the HCF times the
LCM is the product of the numbers.
For example, 2, 4 and 6 have: HCF = 2, LCM = 12, product = 48.
Barnden (SoCS)
Intro to Maths for CS: Numerical Factors(contd from prime-number slides)
Term 1, 2014–15
8/9
Relationship between HCF, LCM and Co-Primeness
Proposition: Two numbers are co-prime if and only if their HCF is 1.
Reason: Direct from the definitions of HCF and co-primeness.
Proposition: Two numbers are co-prime if and only if their LCM is their product.
Reason: Direct from above Proposition and the fact that LCM times HCF =
product.
Examples :
25 and 33 are co-prime, their HCF is 1, and their LCM is 825.
25 and 35 are not co-prime, their HCF is 5, and their LCM is 175.
Barnden (SoCS)
Intro to Maths for CS: Numerical Factors(contd from prime-number slides)
Term 1, 2014–15
9/9
Download