COMPUTER PROBLEMS: DAY 2

advertisement
COMPUTER PROBLEMS:
DAY 2
(1) The following program computes numbers a, b such that gcd(a, b) = am + bn:
def gcdlc(m,n):
# Returns the GCD of m and n and solves:
return lcomb(m,n,1,0,0,1) # am + bn = GCD - returns a,b,GCD
def lcomb(m,n,c,d,e,f): # Works for the module gcdlc
if m==0:
return (n,e,f)
(q,r) = divmod(n,m)
return lcomb(r,m,e-c*q,f-d*q,c,d)
Try it out with a few numbers to convince yourself that it works.
(2) Use gcdlc to find the the inverses of 117 mod 103, 222 mod 17947 and 1234567 mod
1812647.
(3) My date of birth was encoded using the function 1234567 ∗ x mod 1812647. If
f (x) = 1201707, what is my date of birth x?
(4) Write a program that computes the inverse of a mod b. Check that it works
for 117 mod 103 and for 222 mod 17947. What happens for 123 mod 309?
(5) Solve 65657657x + 21344345y = 35.
(6) Write a program that computes the order of 2 mod b (i.e. the smallest power
t such that 2t = 1 mod b). What happens when b is 324?
(7) Factor 1965289 and 828301.
(8) Write a program that generates a random prime with 8 digits.
(9) Write a program that checks if n is a square.
Non-computer problems:
(1) A triangular number is one of the form n(n + 1)/2, where n is a positive
integer. Show that the last digit of a triangular number cannot be 2,4,7 or 9.
(2) Show that if the natural numbers a, b, c satisfy
a2 + b2 = c2
then:
(a) Either a or b is divisible by 3.
(b) Either a or b is divisible by 4.
(c) One of a, b and c is divisible by 5.
1
Download