CS 1050C Practice Test Solutions: Congruences, gcd, and lcm, Exams of Computer Science

Solutions to practice test questions related to congruences, greatest common divisors (gcd), and least common multiples (lcm) for cs 1050c. Topics include the relationship between congruences and divisibility, finding gcd values for n and n+12, and proving functions are onto and one-to-one.

Typology: Exams

Pre 2010

Uploaded on 08/04/2009

koofers-user-k5z
koofers-user-k5z 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Practice test 2 CS 1050C solutions
1. Notice that (all congruences below are modulo 4):
(cncn1. . . c1c0)10 =c0+ 10c1+ 102c2+ 103cc+. . . + 10ncnc0+ 2c1.
The congruence holds because 10 2 and 10n0 for n2. We
conclude that (cncn1. . . c1c0)10 is divisible by 4 (i.e. congruent to
zero modulo 4) if and only if c0+ 2c1is. 2
2. Notice that
gcd(n, n + 12) = gcd(n, n + 12 n) = gcd(n, 12).
This proves that gcd(n, n + 12) is a divisor of 12 for any n, i.e. it is
an element of the set A={1,2,3,4,6,12}. Conversely, any element
aAis a value of gcd(n, n + 12) for some n, for example for n=a
(because gcd(a,12) = a as ais a divisor of 12).
The list of all possible values is 1,2,3,4,6,12.
2
3. We’ll do it directly from definitions here.
First, let’s prove that gis onto. Take any cC. Then, h(c) is an
element of Dso it has to belong to the image of (onto function by
assumptions) hgf: there exists an aAsuch that hgf(a) =
h(g(f(a))) = h(c). Because his a one-to-one function, g(f(a)) = c
(value of hon both sides is the same!). We conclude that cis in the
range of g(it’s the value of gat f(a)). We are done.
Now we need to prove that gis one-to-one. Assume it is not. Then,
there are b, b0Bsuch that b6=b0and g(b) = g(b0). Since fis onto,
there are a, a0Asuch that f(a) = band f(a0) = b0. Obviously, a6=a0
(otherwise, the values of fat these elements would be the same but
they happen to be band b0). Moreover,
hgf(a) = h(g(f(a)) = h(g(b)) = h(g(b0)) = h(g(f(a0))) = hgf(a0).
This contradicts one-to-oneness of hgf.2
4. Assume a, b, c are natural numbers and x, y are integers such that xa +
yb =c. gcd(a, b) is (by definition) a common divisor of aand b:
gcd(a, b)|aand gcd(a, b)|b. Thus, gcd(a, b) divides any integer
combination of aand b, in particular xa +yb =c2
5. Notice that, since ais even,
gcd(a, a + 2) = gcd(a, 2) = 2
(this is because ais an even number so 2 is a common divisor. Clearly,
there are no larger divisors). Now, from one of the theorems we proved
in class,
2lcm(a, a + 2) = gcd(a, a + 2)lcm(a, a + 2) = a(a+ 2).
1
pf2

Partial preview of the text

Download CS 1050C Practice Test Solutions: Congruences, gcd, and lcm and more Exams Computer Science in PDF only on Docsity!

Practice test 2 – CS 1050C – solutions

  1. Notice that (all congruences below are modulo 4):

(cncn− 1... c 1 c 0 ) 10 = c 0 + 10c 1 + 10^2 c 2 + 10^3 cc +... + 10ncn ≡ c 0 + 2c 1.

The congruence holds because 10 ≡ 2 and 10n^ ≡ 0 for n ≥ 2. We conclude that (cncn− 1... c 1 c 0 ) 10 is divisible by 4 (i.e. congruent to zero modulo 4) if and only if c 0 + 2c 1 is. 2

  1. Notice that

gcd(n, n + 12) = gcd(n, n + 12 − n) = gcd(n, 12).

This proves that gcd(n, n + 12) is a divisor of 12 for any n, i.e. it is an element of the set A = { 1 , 2 , 3 , 4 , 6 , 12 }. Conversely, any element a ∈ A is a value of gcd(n, n + 12) for some n, for example for n = a (because gcd(a, 12) = a as a is a divisor of 12). The list of all possible values is 1, 2 , 3 , 4 , 6 , 12. 2

  1. We’ll do it directly from definitions here.

First, let’s prove that g is onto. Take any c ∈ C. Then, h(c) is an element of D so it has to belong to the image of (onto function by assumptions) h ◦ g ◦ f : there exists an a ∈ A such that h ◦ g ◦ f (a) = h(g(f (a))) = h(c). Because h is a one-to-one function, g(f (a)) = c (value of h on both sides is the same!). We conclude that c is in the range of g (it’s the value of g at f (a)). We are done. Now we need to prove that g is one-to-one. Assume it is not. Then, there are b, b′^ ∈ B such that b 6 = b′^ and g(b) = g(b′). Since f is onto, there are a, a′^ ∈ A such that f (a) = b and f (a′) = b′. Obviously, a 6 = a′ (otherwise, the values of f at these elements would be the same but they happen to be b and b′). Moreover,

h◦g◦f (a) = h(g(f (a)) = h(g(b)) = h(g(b′)) = h(g(f (a′))) = h◦g◦f (a′).

This contradicts one-to-oneness of h ◦ g ◦ f. 2

  1. Assume a, b, c are natural numbers and x, y are integers such that xa + yb = c. gcd(a, b) is (by definition) a common divisor of a and b: gcd(a, b) | a and gcd(a, b) | b. Thus, gcd(a, b) divides any integer combination of a and b, in particular xa + yb = c 2
  2. Notice that, since a is even,

gcd(a, a + 2) = gcd(a, 2) = 2

(this is because a is an even number so 2 is a common divisor. Clearly, there are no larger divisors). Now, from one of the theorems we proved in class,

2lcm(a, a + 2) = gcd(a, a + 2)lcm(a, a + 2) = a(a + 2).

We conclude that

lcm(a, a + 2) =

a(a + 2) 2