This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 8. a) Initially y :3. For i = 1 weset y to 3.2+1 = 7. For i :2 we set y to 72+1 = 15, andwe aredone.
b) There is one multiplication and one addition for each of the 71 passes through the loop, so there are n
multiplications and n additions in all. 10. We are asked to compute (2n2 + 2")  10'9 for each of these values of 71. When appropriate, we change the
units from seconds to some larger unit of time. a) 1.224 x 10‘6 seconds b) approximately 1.05 X 10'3 seconds 12. a) The number of comparisons does not depend on the values of (11 through an. Exactly 2n — 1 comparisons
are used, as was determined in Example 1. In other words, the best case performance is b) In the best case {E = all. We saw in Example 4 that three comparisons are used in that case. The best
case performance, then, is 0(1).
c) It is hard to give an exact answer, since it depends on the binary representation of the number n, among
other things. In any case, the best case performance is really not much different from the worst case perfor
mance, namely 0(log n), since the list is essentially cut in half at each iteration, and the algorithm does not
stop until the list has only one element left in it. 20. The algorithm we gave is clearly of linear time complexity, i.e., 0(n), since we were able to keep updating the sum of previous terms, rather than recomputing it each time. This applies in all cases, not just the worst
case. 26. Each iteration (determining whether we can use a coin of a given denomination) takes a bounded amount of tlme, and there are at most n iterations, since each iteration decreases the number of cents remaining.
Therefore there are 0(n) comparisons. 4. Suppose a  b, so that b = at for some t, and b I c, so that c = bs for some 5. Then substituting the ﬁrst
equation into the second, we obtain 0 = (at)s = a(ts). This means that a I c, as desired. 8. The simplest counterexample is provided by a = 4 and b = c : 2. 10. In each case we can carry out the arithmetic on a calculator. a) Since 8 ' 5 = 40 and 44 — 40 = 4, we have quotient 44 div 8 = 5 and remainder 44 mod 8 = 4.
b) Since 21 0 37 = 777, we have quotient 777 div 21 = 37 and remainder 777 mod 21 = 0.
c) As above, we can compute 123 div 19 = 6 and 123 mod 19 = 9. However, since the dividend is negative and the remainder is nonzero, the quotient is ~(6 + 1) = —7 and the remainder is 19 — 9 = 10. To check that
—123 div 19 = —7 and —123 mod 19 = 10, we note that —123 = (—7)(19)+ 10. 12. Assume that a E b (mod m). This means that mla — b, say a — b : me, so that a : b + mc. Now let us
compute a mod m. We know that b = qm + r for some nonnegative r less than m (namely, 7“ = b mod m). Therefore we can write a 2 gm + 7" + me = (q + c)m + 7". By deﬁnition this means that r must also equal
a mod m. That is what we wanted to prove. 16. In each case we just apply the division algorithm (carry out the division) to obtain the quotient and remainder,
as in elementary school. However, if the dividend is negative, we must make sure to make the remainder
positive, which may involve a quotient 1 less than might be expected. a) Since —17 = 2  (—9) + 1, the remainder is 1. That is, —17 mod 2 = 1. Note that we do not write
—17= 2  (—8) — 1, so —17 mod 2 75 —1.
b) Since 144 = 7  20 + 4, the remainder is 4. That is, 144 mod 7 2 4. 20. From a E b (mod m) we know that b = a + 3m for some integer 5. Similarly, d : c + tm. Subtracting, we
have b — d = (a — c) + (s — t)m, which means that a — c E b — d (mod 24. Write n = 2k: + 1 for some integer k. Then n2 = (2k + 1)2 = 4k2 + 419+ 1 = 4k(k + 1) + 1. Since either k
k + 1 is even, 4k(k + 1) is a multiple of 8. Therefore 712 — 1 is a multiple of 8, so 712 E 1 (mod 8). 2. The numbers 19, 101, 107, and 113 are prime, as we can verify by trial division. The numbers 27 = 334 93 = 3 . 31 are not prime. 4. We obtain the answers by trial division. The factorizations are 39 = 3  13, 81 = 34, 101 = 101 i
143 = 11  13, 289 = 172, and 899 = 2931. 8. We follow the hint. There are n numbers in the sequence (n + 1)! + 2, (n + 1)! + 3, (n + 1)! +
(n + 1)! + (n + 1). The ﬁrst of these is composite because it is divisible by 2; the second is composite
it is divisible by 3; the third is composite because it is divisible by 4; . . .; the last is composite b
divisible by n + 1. This gives us the desired n consecutive composite integers. h. We must ﬁnd, by inspection with mental arithmetic, the greatest common divisors of the numbers from 1 to 11 with 12, and list those whose gcd is 1. These are 1, 5, 7, and 11. There are so few since 12 had many
factors—in particular, both 2 and 3. 20. We form the greatest common divisors by ﬁnding the minimum exponent for each prime factor. ’
a) 223352 . b) 2311 0) 17 d) 1 e) 5 f) 2357 24. We have 1000 2 23 53 and 625 = 54, so gcd(1000, 625) = 53 = 125, and lcm(1000,625) = 23 ~ 54 = 5000. As
expected, 125 ‘ 5000 = 625000 2 1000  625. 32. Mom at E b (mod m) we know that b = a + em for some integer 5. Now if d is a common divisor of a and
m, then it divides the righthand side of this equation, so it also divides b. We can rewrite the equation as
a = b — sm, and then by similar reasoning, we see that every common divisor of b and m is also a divisor
of a. This shows that the set of common divisors of a and m is equal to the set of common divisors of b
and 772, so certainly gcd(a, m) = gcd(b, m). 2. To convert from decimal to binary, we successively divide by 2. We write down the remainders so obtained
from right to left; that is the binary representation of the given number.
a) Since 321/2 is 160 with a remainder of 1, the rightmost digit is 1. Then since 160/2 is 80 with a remainder
of 0, the second digit from the right is 0. We continue in this manner, obtaining successive quotients of 40,
20, 10, 5, 2, 1, and 0, and remainders of 0, 0, 0, 0, 1, 0, and 1. Putting all these remainders in order
from right to left we obtain (1 0100 0001)2 as the binary representation. We could, as a check, expand this
binary numeral: 20 + 26 + 28 = 1 + 64 + 256 = 321. 4. a) 1+2+8+16=27 10. Following Example 6, we simply write the hexadecimal equivalents of each group of four binary digits.
Note that we group from the right, so the leftmost group, which is just 1, becomes 0001. Thus we have
(0001 1000 0110 0011)2 = (1863)16. 14. This is exactly the same as what we can do with hexadecimal expansion,4replacing groups of four with groups
of three. Speciﬁcally, convert each octal digit into its 3digit binary equivalent. For example, (306)8 =
(011 000 110);. 16. Since we have procedures for converting both octal and hexadecimal to and from binary (Example 6
Exercises 13*15), to convert from hexadecimal to octal, we ﬁrst convert from hexadecimal to binary and convert from binary to octal. 24. To apply the Euclidean algorithm, we divide the larger number by the smaller, replace .the larger by the sm
and the smaller by the remainder of this division, and repeat this process until the remainder IS 0. At t ‘ point, the smaller number is the greatest common divisor.
a) gcd(1, 5) = gcd(1, 0) = 1 b) gcd(100, 101) = gcd(100, 1) : gcd(1,0) = 1
c) gcd(123, 277) = gcd(123, 31) = gcd(3l, 30) : gcd(30, 1) : gcd(1, 0) = 1 t we need to divide successively by 55, 34, 21, 13, 8, 5, 3, 2, and 1, so 9 divisions are required. The key fact here is that 10 E —1 (mod 11), and so 10’“ E (—1)k (mod 11). Thus 10" is congruent to 1 if k is
even and to —1 if k is odd. Let the decimal expansion of the integer a be given by (an_1an_2 . . . a3a2a1a0)10.
Thus a = 10n‘lan1 + 10n‘2an_2 ++10a1 + (10. Since 10" E (—1)k (mod 11), we have a E ian_1 2F
a._2 +   — a3 + a2 — 01 + a0 (mod 11), where signs alternate and depend on the parity of 71. Therefore
a E 0 (mod 11) if and only if (a0 + a2 + a4 + ~ — (a1 + a3 + a5 + ~  ), which we obtain by collecting the
odd and even indexed terms, is congruent to 0 (mod 11). Since being divisible by 11 is the same as being
congruent to 0 (mod 11), we have proved that a positive integer is divisible by 11 if and only if the sum of its decimal digits in evennumbered positions minus the sum of its decimal digits in oddnumbered positions
is divisible by 11. 50. The partial products are 11100 and 1110000, namely 1110 shifted one place and three places to the left. We
add these two numbers, obtaining 10001100. ...
View
Full Document
 Spring '09
 Khoel

Click to edit the document details