MAT3500 - Number Theory Assignment
Oct. 29th 2024
8
Min.
Assignment on Number Theory
Basic Number Theory - Hoang Anh Duc - MIM - HUS - VNU
Work 2.
Block
Solution:
Block
Work 5.
Block
Solution:
- Let the three consecutive integers be (n), (n+1), and (n+2). We will show that their product (n(n+1)(n+2)) is always divisible by 6 by proving that it is divisible by both 2 and 3.
Block
Work 6.
Block
Solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def decimal_to_base_n(n: int, b: int) -> str:
"""
Convert a decimal number to its representation in base b.
Args:
n: A non-negative integer to convert
b: The target base (2-36)
Returns:
A string representation of the number in base b
Raises:
ValueError: If n is negative or b is not in range [2, 36]
"""
# Input validation
if n < 0:
raise ValueError("Number must be non-negative")
if b < 2 or b > 36:
raise ValueError("Base must be between 2 and 36")
# Special case for n = 0
if n == 0:
return "0"
# Digits for bases > 10
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
# Initialize result
result = []
# Continue division until quotient becomes 0
while n > 0:
# Find rightmost digit (remainder)
remainder = n % b
# Convert digit to proper character representation
result.append(digits[remainder])
# Update n with integer division
n //= b
# Return the reversed string (since we built it backwards)
return "".join(reversed(result))
# Example usage and tests
def test_conversions():
test_cases = [
(25, 2), # Binary
(25, 8), # Octal
(25, 16), # Hexadecimal
(255, 16), # Larger hex number
(1234, 36), # Largest supported base
]
for n, b in test_cases:
result = decimal_to_base_n(n, b)
print(f"{n} in base-{b} is: {result}")
if __name__ == "__main__":
test_conversions()
# Output will be:
# 25 in base-2 is: 11001
# 25 in base-8 is: 31
# 25 in base-16 is: 19
# 255 in base-16 is: FF
# 1234 in base-36 is: YA
PythonWork 9.
Block
Solution:
- .
1
2
3
4
5
1111111 ← carries
1000111
+ 1110111
---------
10111110
Markdown- .
1
2
3
4
5
6
7
8
9
10
11
12
1000111
× 1110111
-----------
1000111 ← (1000111 × 1)
1000111 ← (1000111 × 1)
1000111 ← (1000111 × 1)
1000111 ← (1000111 × 1)
0000000 ← (1000111 × 0)
1000111 ← (1000111 × 1)
1000111 ← (1000111 × 1)
---------------
10000100000001
Markdown- .
1
2
3
4
5
1111111 ← carries
11101111
+ 10111101
-----------
110101100
Markdown- .
1
2
3
4
5
6
7
8
9
10
11
12
13
11101111
× 10111101
-------------
11101111 ← (11101111 × 1)
00000000 ← (11101111 × 0)
11101111 ← (11101111 × 1)
11101111 ← (11101111 × 1)
11101111 ← (11101111 × 1)
11101111 ← (11101111 × 1)
00000000 ← (11101111 × 0)
11101111 ← (11101111 × 1)
-----------------
1011000001110011
MarkdownWork 19.
Block
Solution:
1
2
3
4
5
6
7
8
9
9 = 4(2) + 1
4 = 4(1) + 0
Working backwards:
1 = 9 - 4(2)
1 = 9(1) + 4(-2)
Therefore: 4(-2) ≡ 1 (mod 9)
Answer: -2 ≡ 7 (mod 9)
Markdown1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
141 = 19(7) + 8
19 = 8(2) + 3
8 = 3(2) + 2
3 = 2(1) + 1
2 = 1(2) + 0
Working backwards:
1 = 3 - 2(1)
= 3 - (8 - 3(2))(1)
= 3(3) - 8(1)
= (19 - 8(2))(3) - 8(1)
= 19(3) - 8(7)
= 19(3) - (141 - 19(7))(7)
= 19(52) - 141(7)
Therefore: 19(52) ≡ 1 (mod 141)
Answer: 52
Markdown1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
89 = 55(1) + 34
55 = 34(1) + 21
34 = 21(1) + 13
21 = 13(1) + 8
13 = 8(1) + 5
8 = 5(1) + 3
5 = 3(1) + 2
3 = 2(1) + 1
2 = 1(2) + 0
Working backwards:
1 = 3 - 2(1)
= 3 - (5 - 3(1))(1)
= 3(2) - 5(1)
= (8 - 5(1))(2) - 5(1)
= 8(2) - 5(3)
= (13 - 8(1))(2) - 5(3)
= 13(2) - 8(2) - 5(3)
= 13(2) - (21 - 13(1))(2) - 5(3)
= 13(4) - 21(2) - 5(3)
= (34 - 21(1))(4) - 21(2) - 5(3)
= 34(4) - 21(6) - 5(3)
= (55 - 34(1))(4) - 21(6) - 5(3)
= 55(4) - 34(4) - 21(6) - 5(3)
= (89 - 55(1))(4) - 34(4) - 21(6) - 5(3)
= 89(4) - 55(8)
Therefore: 55(-8) ≡ 1 (mod 89)
Answer: -8 ≡ 81 (mod 89)
Markdown1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
232 = 89(2) + 54
89 = 54(1) + 35
54 = 35(1) + 19
35 = 19(1) + 16
19 = 16(1) + 3
16 = 3(5) + 1
3 = 1(3) + 0
Working backwards:
1 = 16 - 3(5)
= 16 - (19 - 16(1))(5)
= 16(6) - 19(5)
= (35 - 19(1))(6) - 19(5)
= 35(6) - 19(11)
= (54 - 35(1))(6) - 19(11)
= 54(6) - 35(6) - 19(11)
= (89 - 54(1))(6) - 35(6) - 19(11)
= 89(6) - 54(12) - 35(6) - 19(11)
= (232 - 89(2))(6) - 54(12) - 35(6) - 19(11)
= 232(6) - 89(23)
Therefore: 89(-23) ≡ 1 (mod 232)
Answer: -23 ≡ 209 (mod 232)
MarkdownWork 24.
Block
Work 30.
Block