Homework Exercises in Number Theory, Exercises of Programming Methodologies

Homework exercises on number theory, including finding the greatest common divisor of two numbers using recursive and non-recursive methods, applying bezout's theorem, determining if a number is the product of two primes, generating a random number, and calculating the power of a number modulo another number.

Typology: Exercises

2020/2021

Uploaded on 10/28/2022

thanh-duong-nhat
thanh-duong-nhat ๐Ÿ‡ป๐Ÿ‡ณ

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework 10:
Exercise 1. Do the exercises 8.6, 8.7, 8.8 in the textbook.
Exercise 2. A common divisor of m and n is an integer that divides both m and n. The greatest common
divisor, written ๐‘”๐‘๐‘‘โก(๐‘š, ๐‘›), is the largest common divisor of m and n. Write a function to find the
greatest common divisor (gcd) of two numbers in two ways (recursive and not recursive).
Exercise 3. BEZOUTโ€™S THEOREM: If a and b are positive integers, then there exist integers s and t such
that gcd(a, b) = sa + tb. Write a function to find s and t.
Exercise 4. Write a function to determine if a number is the product of two primes.
(hint: if ๐‘› = ๐‘ ร— ๐‘ž, check_prime(p) and check_prime(q)โ€ฆ).
Exercise 5. a) Write the funtion ๐‘Ÿ๐‘Ž๐‘›๐‘‘(๐‘–, ๐‘›) to get a random number in [0; ๐‘›]. The function defined by
๐‘Ÿ๐‘Ž๐‘›๐‘‘(๐‘–, ๐‘› )=(7 โˆ™ ๐‘Ÿ๐‘Ž๐‘›๐‘‘(๐‘– โˆ’ 1, ๐‘›)+ 1) mod ๐‘›,
Where a seed ๐‘Ÿ๐‘Ž๐‘›๐‘‘(0, ๐‘›) = s (import time
s = time.time()).
b) Write function shuffle(alist) to shuffle items in alist.
(Hint: swap alist[i] and alist[rand(i,n)])
Exercise 6. Write a function to calculate (c**s)%z where
๐‘โก = โก1136503834252139, ๐‘  = 2413713104313437โก๐‘Ž๐‘›๐‘‘โก๐‘ง = โก3017141490284017.

Partial preview of the text

Download Homework Exercises in Number Theory and more Exercises Programming Methodologies in PDF only on Docsity!

Homework 10 :

Exercise 1. Do the exercises 8.6, 8.7, 8.8 in the textbook.

Exercise 2. A common divisor of m and n is an integer that divides both m and n. The greatest common

divisor, written ๐‘”๐‘๐‘‘ (๐‘š, ๐‘›), is the largest common divisor of m and n. Write a function to find the greatest common divisor (gcd) of two numbers in two ways (recursive and not recursive).

Exercise 3. BEZOUTโ€™S THEOREM: If a and b are positive integers, then there exist integers s and t such

that gcd(a, b) = sa + tb. Write a function to find s and t.

Exercise 4. Write a function to determine if a number is the product of two primes.

(hint: if ๐‘› = ๐‘ ร— ๐‘ž, check_prime(p) and check_prime(q)โ€ฆ).

Exercise 5. a) Write the funtion ๐‘Ÿ๐‘Ž๐‘›๐‘‘(๐‘–, ๐‘›) to get a random number in [ 0 ; ๐‘›]. The function defined by

๐‘Ÿ๐‘Ž๐‘›๐‘‘(๐‘–, ๐‘›) = ( 7 โˆ™ ๐‘Ÿ๐‘Ž๐‘›๐‘‘(๐‘– โˆ’ 1 , ๐‘›) + 1 ) mod ๐‘›, Where a seed ๐‘Ÿ๐‘Ž๐‘›๐‘‘( 0 , ๐‘›) = s (import time s = time.time()). b) Write function shuffle(alist) to shuffle items in alist. (Hint: swap alist[i] and alist[rand(i,n)])

Exercise 6. Write a function to calculate (c**s)%z where