Some practice problems for midterm 1

Some practice problems for midterm 1
Kiumars Kaveh
October 10, 2011
Problem: (a) What does it mean to say that a numerical algorithm runs in
polynomial time?
Solution: The number of required bit operations to complete the calculation
is at most a constant multiple of a power of the input size in bits. That is, if
n is the input size in bits, then the required bit operations (or equivalently the
time to complete the calculation) is O(nk ) for some fixed k.
(b) List three problems that can be solved in polynomial time.
Solution: There are many correct answers. Here are some.
• The standard algorithms for addition/subtraction are linear time.
• The standard algorithms for multiplication/division are quadratictime.
• The Euclidean algorithm for finding greatest common divisors is cubic
time.
(c) Describe a problem for which no polynomial time solution is known.
Solution: There is no known polynomial time algorithm for finding the prime
factors of an integer.
Problem: Prove that if n is odd, then n2 − 1 is divisible by 8.
Solution: Since n is odd, there is an integer k such that n = 2k + 1 so
n2 − 1 = (2k + 1)2 − 1 = 4k 2 + 4k = 4k(k + 1). Since one of k,k + 1 is even, it
follows that n2 − 1 is divisible by 8.
Alternative solution: An odd number is congruent to 1, 3, 5 or 7 mod 8.
One verifies that for n = 1, 3, 5, 7 we have n2 − 1 ≡ 0 (mod 8).
Problem: Show that if p is prime and x2 ≡ 1(mod p), then either x ≡ 1( mod p)
or x ≡ −1(mod p).
Solution: Since x2 ≡ 1(mod p), we have p|x2 − 1 = (x − 1)(x + 1). Since
p is prime, we must have p|x − 1 or p|x + 1. Equivalently, x ≡ 1(mod p) or
x ≡ −1(mod p).
1
(c) Find four distinct solutions to x2 ≡ 1(mod 15).
Solution: x = 1, x = 4, x = 11, x = 14.
Problem: Let k be a positive integer such that 10|k. Show that we have
5k ≡ 1(mod 11).
Solution: First we show that 510 ≡ 1(mod 11) as follows: 52 = 25 ≡
3 (mod 11), then 54 ≡ 32 = 9 ≡ −2 (mod 11). Thus 58 ≡ (−2)2 ≡ 4 (mod 11)
and hence 510 ≡ 3 · 4 = 12 ≡ 1 (mod 11). Now since 10|k we have k = 10q.
Thus 510 = 510q = (510 )q ≡ 1q ≡ 1 (mod 11) as required.
Problem: Find all distinct solutions modulo 100 for each of the following congruences.
(a) 35x ≡ 20 (mod 100).
Solution: We have gcd(35, 100) = 5. Since 5 is a divisor of 20, the congruence
has 5 distinct solutions. The given congruence has the same integer solutions
as 7x ≡ 4 (mod 20). The smallest non-negative solution is x = 12. The integer
solutions are xk = 12 + 20k where k can be any integer. The 5 distinct solutions
modulo 100 are x0 = 12, x1 = 32, x2 = 52, x3 = 72, x4 = 92.
(b) 35x ≡ 21 (mod 100)
Solution: We have gcd(35, 100) = 5. Since 5 is not a divisor of 21, there are
no solutions.
Problem: (a) List the invertible elements of modulo 10 and find the inverse of
each.
Solution: The invertible elements are exactly the numbers between 1, . . . 9
which are relatively prime with 10, i.e. 1, 3, 7, 9. We have: 1−1 = 1, 3−1 = 7,
7−1 = 3 and 9−1 = 9.
(b) Find 23−1 mod 1000.
Solution:
1000 = 43 · 23 + 11,
23 = 2 · 11 + 1.
so
1
= 23 − 2 · 11,
= 23 − 2(1000 − 43 · 23),
= 87 · 23 − 2 · 1000.
Therefore
87 · 23 ≡ 1 (mod 1000).
2
so 23−1 mod 1000 = 87.
Problem: When 11 pirates attempt to divide up a chest of gold coins evenly,
there are five left over. They toss the smallest pirate overboard and try to divide
the coins among the remaining 10 pirates. This time there are eight left over.
Whats the smallest number of coins that could be in the chest?
Solution: Let x be the number of coins in the chest. We have
x ≡ 5 (mod 11)
x ≡ 8 (mod 10)
The first congruence has solutions x = 5 + 11k. Inserting this into the second equation gives 5 + 11k ≡ 8 (mod 10) or equivalently k ≡ 3 (mod 10).
This means that k = 3 + 10`. Plugging this back into x = 5 + 11k we obtain
x = 5 + 11(3 + 10`) = 38 + 110`. The smallest possible x is when ` = 0, and
x = 38.
Problem: Use mathematical induction to show that for any integer n > 2 we
have 2n > n2 .
Solution: The base case n = 1 is clearly true. Now suppose 2n > n2 (induction hypothesis). We wish to show 2n+1 > (n+1)2 . We have 2n+1 = 2·2n > 2n2 .
Now 2n2 > (n + 1)2 = n2 + 2n + 1 √⇐⇒ n2 > 2n + 1√ ⇐⇒ n2 − 2n + 1 >
2 ⇐⇒ (n − 1)2 > √
2 ⇐⇒ n − 1 > 2 ⇐⇒ n > 1 + 2. Thus we conclude
that if n ≥ 3 > 1 + 2 then (n + 1)2 < 2n2 < 2 · 2n = 2n+1 .
Pn
Problem: Use induction to show that j=1 j · j! = 1 · 1! + 2 · 2! + · + n · n! is
equal to (n + 1)! − 1.
Solution: 1! = 2! − 1 so the formula is clearly true for n = 1. Now suppose
the formula is true for n, we wish to prove it for n + 1. We have:
n+1
X
j · j!
=
n
X
j · j!) + (n + 1)(n + 1)!,
(
=
=
=
(n + 1)! − 1 + (n + 1)(n + 1)!,
(n + 1)!(n + 2) − 1,
(n + 2)! − 1,
j=1
j=1
as required.
Problem: Let n > 1 be an integer and let p be the smallest prime factor of n.
Show that if p > n1/3 then n/p is either a prime or is equal to 1.
Solution. By contradiction, suppose n/p is not a prime or 1. Then n/p
should have at least two prime factors i.e. n/p = p1 · · · pr and r ≥ 2. Thus
n = pp1 · · · pr . Since p is the smallest prime factor of n we have pi > n1/3 . This
implies that n = pp1 · · · pr > (n1/3 )(r+1) ≥ (n1/3 )3 = n which is a contradiction.
3