Modular Arithmetic
Applications
Computing the Day of the Week
❖ A function that is related to the modulo function is called the
floor function
❖ Floor Function
– also called the greatest integer function
– denoted by x
– the greatest integer that is less than or equal to x
Example:
17
3.2 = 3 =4
4
10.96 = 10 −8.5 = -9
1
=0
2
Zeller’s Congruence
Using the floor function, we can write a formula that gives the day of the week
for any date. The formula, known as Zeller’s congruence, is given by:
where,
d – day of the month
m – month where, 1 – March
2 – April, . . .
11 – January
12 – February
c – first 2 digits of the year
y – last 2 digits of the year; if the month is January or February,
y is the last two digits of the year minus 1
x – day of the week using 0 – Sunday,
1 – Monday, . . . ,
6 – Saturday
❑ Example 1:
What day of the week was July 4, 1776?
Solution:
d=4
m=5
c = 17
y = 76
13 5 −1 76 17
x + + + 4 + 76 − 2(17) 𝑚𝑜𝑑 7
5 4 4
12 + 19 + 4 + 4 + 76 − 34 mod 7
81 mod 7
4 , Thursday
❑ Example 2:
What day of the week was January 16, 2000?
Solution:
d = 16
m = 11
c = 20
y = -1 (since the month is January, y = 0-1 = -1)
13(11)−1 −1 20
x + + + 16 + −1 − 2(20) 𝑚𝑜𝑑 7
5 4 4
28 + −1 + 5 + 16 + −1 − 40 mod 7
7 mod 7
0, Sunday
➢ Do it yourself (DIY): What day of the week were you born?
International Standard Book
Number (ISBN)
• a product identifier used by publishers and other supply
chain participants for ordering, and listing sales records and
stocks
• consists of 13 digits, the 13th digit is the check digit.
Let 𝑑1 be the first digit, 𝑑2 the second digit, and so on to the 13th digit.
The check digit, 𝑑13 , is chosen to satisfy the following congruence:
Example:
❑ Check if ISBN 978-0-760-73261-8 is valid.
978-0-760-73261- 8
Solution:
Using the above formula, calculate the check digit as follows.
Notice that we group the digits that are to be multiplied by 3
(the ones that were underlined), and those that are not.
𝑑13 10 – [(9+8+7+0+3+6) + 3(7+0+6+7+2+1)] mod 10
10 – [33 + 3(23)] mod 10
10 – 102 mod 10
10 – 2
8
The check digit matches with the last digit in the given ISBN
number. Therefore, the ISBN is VALID.
❑DIY:
A certain textbook has ISBN
978-971-23-9357-C
where C is the check digit. Find C.
Answer: 0
Universal Product Code (UPC)
• used for commercial identification of products
• a 12-digit number that satisfies a congruence equation that is
similar to the one for ISBNs. The last digit is the check digit.
❑ Example:
Is 1-32342-65973-9 a valid UPC?
Solution:
1-32342-65973- 9
𝑑12 10 – [3(1+2+4+6+9+3) + (3+3+2+5+7)] mod 10
10 – [3(25) + 20] mod 10
10 – 95 mod 10
10 – 5
5
The check digit does not match with the last digit in the given
UPC number. Therefore, the UPC is NOT VALID.
DIY:
➢ What is the missing digit in this UPC?
ANSWER: 2
CREDIT CARD NUMBERS
Credit card numbers are normally 16 digits long. To determine
whether a credit card number is valid or not, we use Luhn’s
algorithm:
1) Read the digits from right to left. Double every other digit
beginning with the 2nd to the last digit. If the answer is a
two-digit number after being doubled, treat the number as
two individual digits.
2) Add the new list of digits. If the card is valid, the sum must
be congruent to 0 mod 10.
Example:
Is the credit card number valid or not?
Reading from right to left, underline every other digit beginning
with the second-to-last digit. Next double each of the underlined
digits.
5 921 7512 3412 3456
10 4 14 2 6 2 6 10
Then add all digits, treating the two-digit numbers as two
single digits.
[(1+0) + 9 +4 +1+(1+4) + 5 +2 +2 +6 +4 +2 +2 +6 +4 (1+0) +6] mod 10
= 60 mod 10
0
Because 60 0 mod 10, the credit card number is VALID.
DIY: Using Luhn’s Algorithm,
determine whether this credit
card is valid or not.
Answer:
68mod 10 ≠ 0, Not Valid