You are on page 1of 21

Integer • Introduction

• Modular
Arithmetic
• GCD, LCM
CSCI 1303 • Number systems
Mathematics for Computing I
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Divisor: Multiple of
dividend quotient • 𝑚 is a multiple of 𝑛
𝑚
=𝑞 • 𝑛 | 𝑚; 𝑛 divides 𝑚
𝑛
divisor
q
dividend divisor n m
𝑚 =𝑞⋅𝑛
quotient
m
hyaacob@iium.edu.my
0
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Division algorithm
• Suppose 𝑚 and 𝑛 are integers and 𝑛 > 0
divisor

dividend
𝑞 = 𝑚 𝑑𝑖𝑣 𝑛
𝑟 = 𝑚 𝑚𝑜𝑑 𝑛
𝒎=𝒒⋅𝒏+𝒓

remainder
quotient
• for integers 𝑞 and 𝑟 with 0 ≤ 𝑟 < 𝑛.
hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

DIV MOD
Integer
Description Modulus
division
Output Quotient Remainder
Notations / %
28 DIV 7 28 MOD 7
Examples
28 / 7 28 % 7
hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11
2 17 6
3 5 6
4 24 6
5 11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11
2 17 6
11 101
3 5 6
4 24 6
5 11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11
9
2 17 6
11 101
3 5 6
4 24 6
5 11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11
9
2 17 6
11 101
3 5 6
4
99
24 6
5 11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11
9
2 17 6
11 101
3 5 6
4
99
24 6
5
2
11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
9
2 17 6
11 101
3 5 6
4
99
24 6
5
2
11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
2 17 6
3 5 6
4 24 6
5 11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
2 17 6 2 5
6 17
3 5 6
4 24 6
5 11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
2
2 17 6 2 5
6 17
3 5 6
4
12
24 6
5
5
11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
2
2 17 6 2 5
6 17
3 5 6
4
12
24 6
5
5
11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2 0
2 17 6 2 5 6 5
0
3 5 6 0 5
5
4 24 6
5 11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
2 17 6 2 5
3 5 6 0 5
4 24 6
5 11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
2 17 6 2 5
3 5 6 0 5
4 24 6 4 0
5 11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
2 17 6 2 5
3 5 6 0 5
4 24 6 4 0
5 11 3
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
2 17 6 2 5
3 5 6 0 5
4 24 6 4 0
5 11 3 3 2
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
2 17 6 2 5
3 5 6 0 5
4 24 6 4 0
5 11 3 3 2
6 -11 3

hyaacob@iium.edu.my
CSCI 1303 - Mathematics for Computing I Integer – Modular Arithmetic

Example
a b a DIV b a MOD b
1 101 11 9 2
-4
2 17 6 2 5
3 -11
3 5 6 0 5
4
-12
24 6 4 0
5
1
11 3 3 2
6 -11 3 -4 1

hyaacob@iium.edu.my

You might also like