Download Solutions to HW3 posted - University of California, Santa Barbara

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CS 40
Spring 2014
University of California, Santa Barbara
CMPSC 40 SPRING 2014
HOMEWORK 3 SOLUTIONS
1. Section 2.5 problem 4
(a) Countable. The integers in the set can be listed as a mapping with the natural numbers as:
-1, 1, -2, 2, -4, 4, -5, 5…..
       
1, 2, 3, 4, 5, 6, 7, 8…..
(b) Countable. The integers in the set can be listed as a mapping with the natural numbers as:
-5, 5, -10, 10, -15, 15, -20, 20, -25, 25, -30, 30,…..
         
 
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,…..
(c) Countable. The numbers can be arranged in a 2-dimensional table as follows:
.1
.1
.11
.111
.1111 . .
1. 1
1
1.1
1.11
1.111 . .
11. 1
11
11.1
11.11
11.111 . .
111. 1 111 111.1 111.11 111.111 . .
.
.
.
.
.
.
.
.
.
.
In this table, each row is a countable set and a union of such countable sets is also countable. For
mapping we can zigzag along the positive-sloping diagonals as follows:
. 1 , 1. 1 , .1, .11, 1, …..
    
1, 2, 3, 4, 5, …..
(d) Uncountable. It can be proved by using the same diagonalization argument used to prove that the
set of all reals is uncountable. All we need to do is choose di = 1 when dii = 9 and choose di = 9 when
dii = 1 or dii is blank (if the decimal expansion is finite).
2. Section 4.1 problem 22
Quotient(Q) = (a div m) and Remainder(R) = (a mod m)
(a) Since the dividend is negative, the remainder must be nonzero which means the quotient will be
negative. So the quotient is −2 and the remainder is −111−(−2)·99 = −111+198 = 87
(b) Similarly Q = −99, R = 0
(c) Q = 10, R = 309
(d) Q = 123, R = 333
3. Section 4.1 problem 24
(a) a = -3; Since 23| (43 - (-3))
(b) a = -12; Since 29| (17 - (-12))
(c) a = 94; Since 21|(94 - (-11))
4. Section 4.2 problem 32
Decimal integer ‘a’ can be expanded as (an 1an  2 an 3 ....a3a2 a1a0 )10 and thus can be expressed as:
a  10n1 an1  10n2 an2  ...  10a1  a0
While 10  −1 (mod 11) and thus 10  (1) (mod11) i.e. 10 is congruent to 1 if k is even and -1 if
k is odd. Thus we will have following expression where signs alternate and depend on the parity of n.
a   an1 an2  ...  a3  a2  a1 (mod11)
k
HW 3 Solutions
k
k
1
CS 40
Spring 2014
Therefore a  0(mod11) when (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 even-numbered positions minus the sum of its decimal digits in oddnumbered positions is divisible by 11
5. Section 4.2 problem 6
For conversion from Base ‘2’ (1bit) to Base ‘8’ (3bits), start by grouping the digits into 3-bit groups
from LSB to MSB and write the octal equivalent of each group
(a) (1111 0111)2 = (011 110 111)2 = (367)8
(b) (1010 1010 1010)2 = (101 010 101 010)2 = (5252)8
(c) (111 0111 0111 0111)2 = (111 011 101 110 111)2 = (73567)8
(d) (101 0101 0101 0101)2 = (101 010 101 010 101)2 = (52525)8
6. Section 4.3 problem 18
(a) Since 6 = 1 + 2 + 3, and these three summands are the only proper divisors of 6, we conclude that
6 is perfect
(b) Similarly 28 = 1 + 2 + 4 + 7 + 14
(c) We need to find all the proper divisors of 2 p 1 (2 p  1) . Certainly all the numbers 1, 2, 4, 8, . . . ,
2 p1 are proper divisors, and their sum is 2 p1 (this is a geometric series). Also each of these divisors
times 2 p1 is also a divisor, and all but the last is proper. Again adding up this geometric series we
find a sum of (2 p  1)(2 p1  1) . There are no other proper divisors. Therefore the sum of all the
divisors is (2 p  1)  (2 p  1)(2 p 1  1)  (2 p  1)(1  2 p 1  1)  (2 p  1)2 p 1 , which is our original
number and thus it is a perfect number.
7. Section 4.3 problem 30
7 8 2 11
3 4
4 4
11
Since GCD(a, b) × LCM(a, b) = a × b; Answer is (2 .3 .5 .7 ) / (2 .3 .5)  (2 .3 .5.7 )
8. Section 4.3 problem 32
To apply the Euclidean algorithm, we divide the larger number by the smaller, replace the larger by
the smaller and the smaller by the remainder of this division, and repeat this process until the
remainder is 0. At that point, the smaller number is the greatest common divisor (GCD)
(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(31, 30) = gcd(30, 1) = gcd(1, 0) = 1
(d) gcd(1529, 14039) = gcd(1529, 278) = gcd(278, 139) = gcd(139, 0) = 139
(e) gcd(1529, 14038) = gcd(1529, 277) = gcd(277, 144) = gcd(144, 133) = gcd(133, 11) = gcd(11, 1) =
gcd(1, 0)= 1
(f) gcd(11111, 111111) = gcd(11111, 1) = gcd(1, 0) = 1
HW 3 Solutions
2