Course
Introduction
By- Dr. Ankur Gupta
CS01: Mathematics-I
1
Mathematics Team
Class Instructor:
●
Dr. Ankur Gupta
Lab Instructors:
●
Gurkiran Kaur
●
Badal Kumar
●
Bhavishya Rao
●
Amit Patel
Course: Mathematics for
Computer Science 1
3
The broader picture
MATHEMATICS
Robotics
Cyber Security
AI and ML
Computer Science
Maths is the way to development
Maths is the way to competitive programming
ICPC 2023 World Finals
Maths is the way to Machine Learning
Maths is the way to Pathfinding Algorithms
Maths is the way to Cryptography
1st Year Maths Roadmap
●
●
Semester 1 : Mathematics for Computer Science-1
Semester 2: Probability and Statistics
Sem-1 Mathematics Roadmap
Propositional
Logic
Set Theory
Functions
Recursion and
Recurrence Relations
Arithmetic
Foundations
Graph Theory
Predicate
Logic &
Quantifiers
Proving Techniques
& Mathematical
Induction
Combinatorics
Evaluation Components
Component
Contests
Mid Sem
Assignments
End Sem
Class
Participation
Weightage
10%
20%
20%
40%
10%
General course policies
●
Minimum 75% attendance is compulsory to sit in Mid-sem and End-semester
exam.
●
Attendance will be marked through biometric.
●
Join the lecture from portal in the starting of lecture.
●
Give feedback at the end of lecture.
●
Labs in two separate sections.
Classroom Rules
●
No entry after the commencement of class time.
●
If found talking, have to discuss it with the rest of the class.
●
If found sleeping need to come ahead and study standing for rest of the
class.
●
Mobile Phones should be in DND mode and should not be used during class
time.
Welcome Class of 2029
for Mathematics for
Computer Science-1
Course
��
There is magic in Mathematics 😲
●
Pick any 2-digit
number
●
Add both the digits
●
Subtract the sum from
the chosen 2-digit
number
●
Focus on the shape
next to the final
number
There is magic in Mathematics 😲
Did you get Pentagon?
There is magic in Mathematics 😲
●
Pick any 2-digit number
●
Add both the digits
●
Subtract the sum from the chosen 2-digit number
●
Focus on the shape next to the final number
Did you get Pentagon?
➔
2-digit number, n = 10a + b
➔
Sum of digits = a + b
➔
Final number = (10a + b) - (a + b) = 9a
➔
All the multiples of 9 contain Pentagon.
Reversal Difference Puzzle 🔄
Instructions:
●
Step 1: Pick any 2-digit number (where digits are not the same).
●
Step 2: Reverse the digits to form a new number.
●
Step 3: Subtract the smaller number from the larger.
💡 Try different 2-digit numbers!
👉 Did you observe any pattern from the results obtained?
Expected Output: You always get a multiple of 9.
But why does this happen?
Reversal Difference Puzzle 🔄
But why does this happen?
➢
ab → 10a + b
➢
ba → 10b + a
➢
Now, ab - ba = (10a + b) - (10b + a) = 9a - 9b = 9(a-b) which indicates that the
result is always a multiple of 9.
Reversal Sum Puzzle 🔄
Instructions:
●
Step 1: Pick any 2-digit number
●
Step 2: Reverse the digits to form a new number.
●
Step 3: Add these two numbers.
💡 Try different 2-digit numbers!
👉 Did you observe any pattern from the results obtained?
Expected Output: You always get a multiple of 11.
Reversal Sum Puzzle 🔄
But why does this happen?
➢
ab → 10a + b
➢
ba → 10b + a
➢
Now, ab + ba = (10a + b) + (10b + a) = 11a + 11b = 11(a+b) which indicates that
the result is always a multiple of 11.
Art of Problem Solving
Task:
Connect the Points without
intersecting Path:
● A to A’
● B to B’
● C to C’
Art of Problem Solving
Art of Problem Solving
Art of Problem Solving
Art of Problem Solving
Burning Wires
🪢 Scenario:
● You are given 2 identical wires.
● Each wire takes exactly 60 minutes to burn completely from one end to the other.
💡 Conditions:
➔ You can light either end or both ends of a wire at the same time.
➔ You are not allowed to break or cut the wires.
➔ You cannot measure or mark the wires.
🤔 Challenge: How can you measure 45 minutes using these two identical wires?
Crossing the Bridge Puzzle
Crossing the Bridge Puzzle
🌉 Scenario:
● 4 people (🧍A, 🧍B, 🧍C, and 🧍D) need to cross a bridge at night.
● At most two people can cross the bridge at the same time.
● When two people cross together, they must move at the slower person's pace.
● They have one torch, and they can't cross the bridge without it.
⏱ Crossing Times:
➔ A takes 1 minute to cross.
➔ B takes 2 minutes to cross.
➔
➔
C takes 5 minutes to cross.
D takes 8 minutes to cross.
🤔 Challenge: Get all 4 people across the bridge in the shortest time possible.
Crossing the Bridge Puzzle
A and B
2 min
A
1 min
C and D
8 min
B
2 min
A and B
2 min
Two Buckets Puzzle
You are given two empty buckets.
- One bucket can hold 3 liters
- Another bucket can hold 5 liters
You have an unlimited supply of water.
How can you measure exactly 4 liters of water?
Two Buckets Puzzle
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Patterns in Mathematics
34
Pattern in Numbers
●
1, 1, 1, 1, 1, 1, 1, ... (All 1’s)
●
1, 2, 3, 4, 5, 6, 7, ... (Counting numbers)
●
1, 3, 5, 7, 9, 11, 13, ... (Odd numbers)
●
2, 4, 6, 8, 10, 12, 14, ... (Even numbers)
●
1, 3, 6, 10, 15, 21, 28, ... (Triangular numbers)
●
1, 4, 9, 16, 25, 36, 49, ... (Squares)
●
1, 8, 27, 64, 125, 216, ... (Cubes)
Visualising Numbers
●
Regular Polygons: The number of equal sides and
angles increases sequentially from 3 (triangle) to 10
(decagon), illustrating geometric growth in symmetry.
●
Graph consists of Vertices and Edges.
○ Complete graph is a graph where every pair of
distinct vertices is connected by a single edge.
○ Complete graph with x vertices is denoted by Kx.
●
1, 4, 9, 16, 25, 36, 49, ... (Squares)
●
Stacked Triangles: Triangles are stacked to form
larger equilateral triangles, increasing in complexity at
each step.
●
Koch Snowflake: Begins with an equilateral triangle,
and with each step, triangular bumps are added to
each side, creating an increasingly intricate snowflake
pattern. Think over it!!! 🤔
Example
Q. Given a cyclical pattern with three colors.
What color is 136?
Ans. Blue / Green / Orange.
38
Example
Q. Given a cyclical pattern with three colors.
What color is 136?
Ans. Blue
136 % 3 = 1
Since numbers that leave a remainder of 1
when divided by 3 are blue, 136 is blue.
39
Algebra Trap
What’s wrong with the following proof?
40
See You Guys
in Next
Session :)
Basic Arithmetic
Foundations
By- Dr. Ankur Gupta
CS01: Mathematics-I
1
Example
What is the sum of all of the numbers in
this square?
Ans. 125
2
Strategic Arithmetics
Arithmetics:
●
Deals with the basic operations of numbers, such as
addition, subtraction, multiplication, and division.
Strategic Arithmetics:
●
Doing arithmetic operations more fast and with little
calculation on
○
Numbers using rearrangement and regrouping
○
Fractions understanding their real life analogy
3
Example
Which is larger?
or
Ans. Both are equal.
4
The Hack
●
●
Whenever you have○
Sum of values
value like:
like:
○
Product of values like:
Always be ready to rearrange and regroup them to find some pattern to
solve it fast and easy
5
Example
●
What's the value of this expression?
Ans. 3
6
Example
What is the sum of all of the numbers in
this square?
Ans. 88
7
Number Theory
8
Natural Numbers
●
Natural numbers are the numbers that we
generally use for counting, or enumerating
items.
●
Natural Numbers: 1, 2, 3, 4, 5, 6, 7, …
●
The set of Natural numbers is denoted by ℕ.
9
Sum of n natural numbers
10
Whole Numbers
●
Whole numbers are all the non-negative
integers. This means the set includes 0 and
all positive counting numbers.
●
Whole Numbers: 0, 1, 2, 3, 4, 5, 6, 7, …
●
The set of Whole numbers is denoted by W.
11
Integers
●
The set of integers adds the opposites of the natural numbers to the set of
whole numbers: {...,−3,−2,−1, 0, 1, 2, 3,...}.
●
0 is neither positive nor negative.
●
The set of Integers is denoted by ℤ (from German "Zahlen").
12
Rapid Fire
● Even + Even = Even
● Even x Even = Even
● Even / Even can be Even or
Odd or Not an Integer
13
Rapid Fire
● Odd + Odd = Even
● Odd x Odd = Odd
● Odd / Odd can be Odd or
not an Integer
14
Rapid Fire
● Even + Odd = Odd
● Even x Odd = Even
● Even / Odd can be Even or Odd
or Not an Integer
● Odd / Even is not an Integer
15
Strategic Arithmetics
on fractions
16
Rational Numbers (Fractions)
●
A rational number (fraction) is any number that can be written in the form
where p, q ∈ ℤ
q≠0
●
1 slice out of 8 slices of Pizza → ⅛ fraction
17
Example
Which number is bigger?
or
18
Example: The Big Race
Kartik, Abhi, Kritika and Manasa are getting ready for the university race.
19
Example: The Big Race
While Abhi and Manasa have been training on their own, Kartik and Kritika have
been practicing for months against each other before the big race. So far they
have had 100 practice races and Kartik and Kritika have won half the races each.
What fraction of races has Kritika won so far?
20
Example: The Big Race
While Abhi and Manasa have been training on their own, Kartik and Kritika have
been practicing for months against each other before the big race. So far they
have had 100 practice races and Kartik and Kritika have won half the races each.
What fraction of races has Kritika won so far?
21
Example: The Big Race
Kritika is getting frustrated with being neck to neck with Kartik. She decides to
use a secret weapon and then easily win their next practice match. What fraction
of races has she now won?
22
Example: The Big Race
Kritika is getting frustrated with being neck to neck with Kartik. She decides to
use a secret weapon and then easily win their next practice match. What fraction
of races has she now won?
23
Example: The Big Race
Who is now in the lead?
Kartik or Kritika
24
Example: The Big Race
Who is now in the lead?
Ans. Kritika
25
Attention
Earlier matches won by Kritika:
Matches won by Kritika now:
Result: Not leading
Result: Leading
Which number should be bigger?
or
26
Example: The Big Race
The problem we gave you earlier was which of these two fractions is
bigger:
or
Can you see a connection between that problem and Kartik and Kritika’s
practice matches?
27
Example
Is this statement true or false?
28
Comparing Fractions using Cross Multiplication
29
Comparing Fractions using Cross Multiplication
●
This method avoids converting to decimals
or finding LCMs.
●
It works because you're effectively
comparing both fractions after multiplying by
the same denominator. 💡
Does the cross multiplication method for
comparing fractions work for negative fractions
too?🤔
30
Example
What fraction of the shape is shaded?
Ans. 7/24
31
Example
Remove color from parts of the square so that 3/4 of it remains shaded.
32
Example
Remove color from parts of the square so that 3/4 of it remains shaded.
33
Example
Shade ⅜ of the square.
34
Example
Shade ⅜ of the square.
35
Properties of Number System
36
Addition on Natural Numbers satisfies
●
Commutative Property
a+b=b+a
●
Associative Property
(a+b)+c=a+(b+c)
37
Addition on Integers satisfies
●
Commutative Property
a+b=b+a
●
Associative Property
(a+b)+c=a+(b+c)
●
Additive Identity
a+0=a
●
Additive Inverse
a+(−a)=0
38
Addition on Rational Numbers satisfies
●
Commutative Property
a+b=b+a
●
Associative Property
(a+b)+c=a+(b+c)
●
Additive Identity
a+0=a
●
Additive Inverse
a+(−a)=0
39
Multiplication on Natural Numbers satisfies
●
Commutative Property
axb=bxa
●
Associative Property
(a x b) x c = a x (b x c)
●
Multiplicative Identity
ax1=a
40
Multiplication on Integers satisfies
●
Commutative Property
axb=bxa
●
Associative Property
(a x b) x c = a x (b x c)
●
Multiplicative Identity
ax1=a
41
Multiplication on Rational Numbers satisfies
●
Commutative Property
axb=bxa
●
Associative Property
(a x b) x c = a x (b x c)
●
Multiplicative Identity
ax1=a
●
Multiplicative Inverse (Division)
a x b = 1 where b = 1/a which is a rational number
42
See You Guys
in Next
Session :)
Basic Arithmetic
Foundations (Part 2)
By- Dr. Ankur Gupta
CS01: Mathematics-I
1
Join the class
2
Today’s Agenda
●
Exponentiation
●
Logarithms
●
Prime Factorization
●
Number of Positive Divisors
3
Exponentiation
4
Exponentiation (ab)
●
Exponentiation is a mathematical operation used to express repeated
multiplication of the same number.
●
If 𝑎 is a number and 𝑛 is a positive integer, then
➢
➢
𝑎 is the base
𝑛 is the exponent (or power)
●
Multiplication is repeated addition.
○ 2*4=2+2+2+2
●
Exponentiation is repeated multiplication.
○ 24 = 2 * 2 * 2 * 2
5
Exponentiation (ab)
6
Example
Ramesh is using an app to track his fitness. The app
requires him to double his effort everyday. He starts with
travelling 2 steps on day 1. How many steps he is required to
take on Day 20?
1048576 Steps
7
Example
What is 128⋅256?
● 214
● 215
● 216
● 217
8
Product rule for Exponents
9
Exponentiation (ab)
10
Why Logarithms?
●
Exponentiation answers:
👉 “What happens when you repeatedly multiply a number?”
●
While logarithms reverse this process:
👉 “How many times must I multiply a number to get a result?”
●
Logarithms are the inverse of exponentiation, just like subtraction is the
inverse of addition.
11
Logarithms
where
● a and b are positive
real numbers
● a ≠ 1 (Why???)
12
Example
Write the following exponentiation in logarithmic form.
1)
103 = 1000
=> 3 = log10 1000
2)
81/3 = 2
=> ⅓ = log8 2
3)
5-3 = 1/125
=> -3 = log5 1/125
13
Logarithms
●
‘e’ refers to Euler's number, which is approximately 2.71828.
●
‘e’ is a mathematical constant that is the base of the natural logarithm and
the exponential function.
14
Logarithms
15
Rapid Fire
● logba = 1 / logab
➔ True
➔
Use change of base property and inverse rule
of
logarithms
to
prove
it.
logba = logaa / logab = 1 / logab
16
Activity Time!!
Select any number from 1 to 100.
In how many guesses can you tell what is the number?
17
Rapid fire
Given two programs:
● Program A runs n number of times
● Program B runs log2n
Which program is more efficient as the input size n increases
18
100 Doors Problem
●
●
There is a hallway of 100 doors.
100 people numbered 1 to 100 are standing in this long hallway that has 100
closed doors also numbered 1 to 100:
●
Person 1 walks down the hallway and opens every door:
19
●
Person 2 walks down the hallway and closes every door that is a multiple of 2:
●
Person 3 walks down the hallway and changes every door that is a multiple
of 3. That is, if the door is open, they close it, and if it is closed, they open it:
20
●
Person 4 changes every door that is a multiple of 4, Person 5 every door
that is a multiple of 5, etc. This continues until all 100 people have walked
down the hallway and changed their doors.
Q. How many times door no. 88 is changed?
21
Prime Factorization
●
What are Prime numbers?
○
●
What are factors?
○
●
Any number which is only divisible by 1 and the number itself.
Numbers that divide another number without leaving a remainder.
What is prime factorization?
○
Prime factorization is the process of expressing a number as a product of
its prime factors.
22
Prime Factorization
●
Example:
○
Prime factorisation of 36 = 6 x 6 = (2 x 3) x (2 x 3) = 22 x 32
■
○
Prime factorisation of 60 = 10 x 6 = (2 x 5) x (2 x 3) = 22 x 3 x 5
■
●
Number of prime factors of 36 = 4 (with repetition) or 2 (distinct)
Number of prime factors of 60 = 4 (with repetition) or 3 (distinct)
Methods to find the Prime Factorisation of any number:
○
Factor Tree Method
○
Repeated Division Method
23
Factor Tree Method
●
Prime factorization of 300 = 2 × 2 × 3 × 5 × 5 = 22 × 3 × 52
24
Repeated Division Method
25
Fundamental Theorem of Arithmetic
●
By the fundamental theorem of arithmetic, every integer greater than 1 can be
uniquely represented as a product of prime numbers.
26
Example:
Scenario:
You have a pizza that is cut into 300 slices. You
need to determine the number of all the possible
group sizes that can share the pizza evenly,
meaning no slices are left over.
27
Finding number of divisors from Prime Factorization
28
Finding number of divisors from Prime Factorization
29
Example: Dividing the pizza
Ans.
●
●
Prime factorization of 300 = 2 × 2 × 3 × 5 × 5
= 22 × 3 × 5 2
Number of positive divisors of 300
= (2 + 1) x (1 + 1) x (2 + 1)
=3x2x3
= 18
30
●
Person 4 changes every door that is a multiple of 4, Person 5 every door
that is a multiple of 5, etc. This continues until all 100 people have walked
down the hallway and changed their doors.
Q. How many times door no. 88 is changed?
Approach: We need to find the number of positive divisors of 88.
➔ Prime factorisation of 88: 88 = 23 × 11
➔ Number of positive divisors of 88 = (3+1) x (1+1) = 4 x 2 = 8
➔ So, door no. 88 is changed 8 times.
31
100 Doors Challenge
●
●
●
There are 100 closed doors in a row, numbered from 1 to 100.
You make 100 passes by the doors. On the ith pass, you toggle every ith door.
Each "toggle" means:
○ If the door is closed, you open it.
○ If the door is open, you close it.
Question:
After 100 passes, which doors remain open?
32
Understanding Divisor Pairs
●
When you find all the divisors (factors) of a number, they usually come in
pairs.
●
Example:
n = 12 → Divisors of 12 are 1, 2, 3, 4, 6, 12.
These form pairs that multiply to 12:
❖ 1×12
❖ 2×6
❖ 3×4
→ Total of 6 divisors = 3 pairs × 2
33
Understanding Divisor Pairs
●
Example:
n = 36 → Divisors of 36 are 1, 2, 3, 4, 6, 9, 12, 18, 36.
These form pairs that multiply to 36:
❖ 1×36
❖ 2×18
❖ 3×12
❖ 4×9
❖ 6×6 ← notice this!
Here, 6×6=36, so both factors are the same. This is called a repeated pair, and it
is only counted once.
→ Total of 9 divisors, which is odd.
34
Understanding Divisor Pairs
n is not a perfect square
n is a perfect square
all divisor pairs are distinct
one pair contains repetition
even number of divisors
odd number of divisors
door toggles even number of
times, i.e., door is closed
door toggles odd number of
times, i.e., door is open
35
100 Doors Challenge
Question:
After 100 passes, which doors remain open?
36
100 Doors Challenge
Question:
After 100 passes, which doors remain open?
Solution:
● Only doors with perfect square numbers will remain open, i.e., the doors
numbered 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.
● So, overall, 10 doors out of 100 doors will remain open.
37
Key Takeaways
Today we learnt:
●
Exponentiation & Logarithms.
●
Doing prime factorization.
●
Finding number of divisors using prime factors.
38
See You Guys in
Next Session :)
Basic Arithmetic
Foundations (Part 3)
By- Dr. Ankur Gupta
CS01: Mathematics-I
1
Today’s Agenda
●
LCM
●
GCD
●
Euclidean Algorithm on Numbers
●
Co-prime numbers
2
Final Thought on Fundamental Theorem of Arithmetic
“What seems obvious to the child becomes awe-inspiring to the philosopher.”
Uniqueness of prime factorization is not trivial.
It is a miracle of structure — and we must pause to appreciate it.
3
Perfect Number
●
A Perfect Number is a positive integer where the sum of its proper divisors
(divisors other than itself) adds back to itself.
Example 1: Consider 6
Example 2: Consider 28
●
●
●
●
●
●
●
Divisors of 6 are 1, 2, 3, 6.
Proper divisors are 1, 2, 3.
Sum of proper divisors:
1+2+3=6
Therefore, 6 is a perfect number.
●
Divisors of 28 are 1, 2, 4, 7, 14, 28.
Proper divisors are 1, 2, 4, 7, 14.
Sum of proper divisors:
1 + 2 + 4 + 7 + 14 = 28
Therefore, 28 is a perfect number.
4
Twin Prime Conjecture
●
In the list of primes, it is sometimes true that consecutive odd numbers are
prime (Twin Primes).
●
Examples: (3,5), (5,7), (11,13), (17,19), (29,31), (41,43), (59,61), (71,73),...
●
Question: Are there infinitely many twin primes?
5
Goldbach Conjecture
●
●
Every even integer greater than 2 can be expressed as the sum of two prime
numbers.
Examples:
○ 4=2+2
○ 6=3+3
○ 8=3+5
○ 10 = 3 + 7 = 5 + 5
○ 12 = 5 + 7,...
Can you prove it?
6
Do you want to earn millions?
Solve!
●
While mathematicians have found very large twin primes, no proof exists
that the number of twin primes is infinite.
●
Goldbach Conjecture has been verified for extremely large numbers (up to
4 × 10¹⁸), but no general proof exists according to Wikipedia.
●
So, Twin Prime Conjecture and Goldbach Conjecture both are
unsolved [with prize money in millions!].
●
Terence Tao is working on these!
7
Terence Tao’s Strategy
●
STEP 1: Collect data — write down numbers (by hand or on computer).
●
STEP 2: Look for patterns and relationships.
●
STEP 3: Make a guess, formulate a conjecture.
●
STEP 4: Test your conjecture on more examples.
●
STEP 5: Try to prove it!
Voila! 🎉
💡 It takes patience, practice, and perseverance to follow these 5 steps — but the
reward is deep mathematical insight.
8
Introduction to Division
9
10
The Division Algorithm
11
Rapid fire
Can
the
remainder
ever
be
negative?
Answer: No
➔
If we allow negative remainder, then we lose the uniqueness
property of division algorithm.
➔
Remainder is defined to be non-negative in math because
we want the remainder to represent a "leftover" quantity. So,
it should always be a small, clean, and positive offset.
12
Problems on Divisibility
13
14
Problems on Divisibility
Observed Pattern:
The product of any k consecutive integers is divisible by k!.
🤯
15
Problems on Divisibility
●
●
235 leaves remainder 2 when divided by 3.
So, 235 - 1 leaves remainder 2 - 1 = 1 when divided by 3.
16
100 Doors Revisited
●
●
Let's take a look at the hallway of 100 doors.
In the hallway of 100 doors, 100 people numbered 1 to 100 are standing in a
long hallway that has 100 closed doors also numbered 1 to 100:
●
Person 1 walks down the hallway and opens every door:
17
●
Person 2 walks down the hallway and closes every door that is a multiple of 2:
●
Person 3 walks down the hallway and changes every door that is a multiple
of 3. That is, if the door is open, they close it, and if it is closed, they open it:
18
●
Person 4 changes every door that is a multiple of 4, Person 5 every door
that is a multiple of 5, etc. This continues until all 100 people have walked
down the hallway and changed their doors.
Question:
What is the number of the first door changed by both Person 6 and Person 8?
19
Lowest Common Multiple
●
Person 6 changes the doors that are multiples of 6:
6, 12, 18, 24, 30, 36……….
●
Person 8 changes the doors that are multiples of 8:
8, 16, 24, 32, 40………..
Question:
What is the number of the first door changed by both Person 6 and Person 8?
→ 24
20
Lowest Common Multiple
Q. Find the LCM of 294 and 364.
21
Finding LCM using Prime Factorization
Ans. 7644
22
Example
Earth rotates around the sun in 365 days and Venus rotates around the sun in 730
days. Whenever Earth and Venus cross each other, a unique phenomenon occurs
due to which the population of the Olive Ridley turtle reduces to half. Considering
the initial population of Olive Ridley turtle is 10000, what will their population after
10 years?
23
Example
Earth rotates around the sun in 365 days and Venus rotates around the sun in 730
days. Whenever Earth and Venus cross each other, a unique phenomenon occurs
due to which the population of the Olive Ridley turtle reduces to half. Considering
the initial population of Olive Ridley turtle is 10000, what will their population after
10 years?
Ans. LCM = 730
3650/730 days=5 crossings
Final Population=10000×(1/2)^5
=312.5 = 312
24
Example
Q. Three runners Manshu, Pintu, and Dally who are running around a circular
track can complete one lap in 250, 400, and 600 seconds, respectively. After how
long will they meet at the starting point next if they start together?
25
Example
Q. Three runners Manshu, Pintu, and Dally who are running around a circular
track can complete one lap in 250, 400, and 600 seconds, respectively. After how
long will they meet at the starting point next if they start together?
Ans= 6000 seconds = 60 mins
26
Example
What is the largest size of square tiles you can use to tile a 24×30 rectangle if all
the tiles must be the same size?
Ans.
Greatest divisor= 6
So largest square tile size can be 6*6.
27
Greatest Common Divisor
●
If a and b are arbitrary integers, and if d is a common divisor, and when one of the
integers is non-zero, then there will be a “finite” number of positive common
divisors for a and b. The greatest among them is the GCD.
●
Mathematical Definition: Let a and b be given integers, with at least one of them
different from 0. An integer d is the Greatest Common Divisor of a and b, denoted
as gcd(a, b), if:
○ 1. d | a and d | b (i.e., d is a common divisor)
○ 2. If c | a and c | b for any integer c, then c ≤ d. (i.e., d is the greatest
among common divisors)
●
GCD is also called as Highest Common Factor (HCF).
28
Greatest Common Divisor
Q. Find the GCD of 294 and 364.
29
How to Find GCD? (School Days Method)
▶ Method 1: Listing Divisors
1. Find all divisors of a.
2. Find all divisors of b.
3. List their common divisors.
4. Find the greatest among the common divisors.
▶ Limitation: It is cumbersome for big a and b.
30
Finding GCD using Prime Factorization
31
Efficient Way to Find GCD: Euclidean Algorithm
●
●
The idea is to use the repeated application of the Division Algorithm.
Euclid wrote about this in his 7th book, ”Elements”.
32
Euclidean Algorithm
33
Euclidean Algorithm
34
Finding GCD using Euclidean Algorithm
Compute GCD(1701, 3768)
●
●
●
●
●
●
●
3768 = 2 × 1701 + 366
1701 = 4 × 366 + 237
366 = 1 × 237 + 129
237 = 1 × 129 + 108
129 = 1 × 108 + 21
108 = 5 × 21 + 3
21 = 7 × 3 + 0 (STOP!, GCD = 3)
Imagine, how much time method 1 will take? (Computational Thinking)
35
Euclidean Algorithm for finding GCD of 2 numbers
Question: Find the GCD of 48 and 18.
Solution:
Apply Division Algorithm:
●
●
●
Step 1: 48 = 2 x 18 + 12
Step 2: 18 = 1 x 12 + 6
Step 3: 12 = 2 x 6 + 0
So, gcd(48, 18) = 6
36
Relation between LCM and GCD
The product of the LCM and GCD of two numbers equals the product of the
numbers themselves: gcd(a, b) × lcm(a, b) = a × b
●
LCM(12,15) × GCD(12,15) = 12×15
●
60×3 = 180, and 12×15 = 180
37
Example
You have two positive integers, A and B, with the following properties:
1.
The Least Common Multiple (LCM) of A and B is 90.
2.
The Greatest Common Divisor (GCD) of A and B is 3.
3.
The sum of A and B is 33.
What is A and B?
Ans.
A+B=33
A×B=270
A=18 and B=15
A=15 and B=18
38
Example
Q. Find sum of two positive integers x and y such that the LCM of x and y is 360
and their GCD is 15.
39
Example
Given the numbers 35 and 64, identify the common divisors of these two numbers.
Ans: 1
40
Relatively Prime
If gcd(𝑎, 𝑏) = 1, we say that 𝑎 and 𝑏 are relatively prime.
Ex: gcd(17, 11) = 1
41
Relatively Prime
Example 1: gcd(7,9) = 1
So, 7 and 9 are relatively prime numbers.
Example 2: gcd(8,10) = 2
So, 8 and 10 are not relatively prime
numbers.
42
Example
Q. How many of the numbers 1, 2, 3 ,…, 100 are relatively prime to 101?
Ans: 100
43
Key Takeaways
Today we learnt :
●
●
●
●
LCM
GCD
Euclidean Algorithm on Numbers
Co-prime numbers
44
See You Guys
in Next
Session :)
Basic Arithmetic
Foundations (Part 4)
By- Dr. Ankur Gupta
CS01: Mathematics-I
1
Today’s Agenda
●
Modular Arithmetic
○
Modular Addition
○
Modular Multiplication
○
Modular Subtraction
○
Modular Exponentiation
2
Modulus Operator
3
Rapid fire
What are the possible remainders
when an integer
𝑛 (positive or
negative) is divided by 9?
Possible remainders:
{0, 1, 2, 3, 4, 5, 6, 7, 8}
0 <= (n mod 9) < 9
4
Cyclic Nature of Modulus
●
●
●
●
●
●
●
0%3 = 0
1%3 = 1
2%3 = 2
3%3 = 0
4%3 = 1
5%3 = 2
6%3 = 0
Note: The value of a%3 will always be either 0 or 1 or 2.
5
Example
What is the value of 8 mod 4?
●
With a modulus of 4, we make a clock with numbers 0, 1, 2, 3.
●
We start at 0 and go through 8 numbers in a clockwise sequence 1, 2, 3, 0, 1,
2, 3, 0.
●
We ended up at 0, So 8 mod 4 = 0.
6
Example
What is the value of -5 mod 3?
●
With a modulus of 3 we make a clock with numbers 0, 1, 2.
●
We start at 0 and go through 5 numbers in counter-clockwise sequence.
●
(5 is negative) 2, 1, 0, 2, 1.
●
We ended up at 1 so -5 mod 3 = 1
7
Example
What is the value of -5 mod 3?
= (-5 + 3) mod 3.
= -2 mod 3
= (-2 + 3) mod 3
= 1 mod 3
=1
Note: m mod n = (m + k⋅n) mod n, where m, k, n are integers.
8
Logic to find m mod n when m < 0
We need to find smallest positive integer ‘k’ such that m + k⋅n ≥ 0.
The value of m + k⋅n will be the result of m mod n.
Note: m mod n = (m + k⋅n) mod n
9
Example
In a 12-hour clock, what time is it 35 hours after 9 o’clock?
Ans: (9+35) mod 12 = 44 mod 12 = 8 o’clock
10
Example
In a 12-hour clock, What time is it 8 hours before 3 o’clock?
Ans: (3-8) mod 12 = -5 mod 12 = 7 o’clock
11
Traditional Division v/s Modulo Perspective
12
What happens when Remainders are Equal?
▶ If r1 ≠ r2 when a and b are divided by n (where n is a positive integer), then
it’s NOT INTERESTING.
▶ If r1 = r2 when a and b are divided by n (where n is a positive integer), we
use the notation:
a ≡ b (mod n)
▶ This is read as “a is congruent to b modulo n”.
13
Congruence: Not a New Concept
▶ The word ”congruent” is familiar from school
(e.g., congruent triangles, △ABC ≅ △PQR).
▶ In number theory, congruence is between remainders of a and b
when divided (reduced) by n.
14
From Remainders to Divisibility
▶ From a = q1n + r and b = q2n + r:
a − q 1n = r
b − q 2n = r
▶ Equating the remainders: a − q1n = b − q2n
▶ Rearranging: a − b = (q1 − q2)n
▶ This implies a − b = kn for some integer k.
▶ Therefore, n divides (a − b), written as n|(a − b).
15
General Notation
●
𝑎 ≡ 𝑏 (mod 𝑛)
●
It also indicates that n divides (a - b) which means that (a - b) is a multiple
of n, i.e., (a - b) can be written as n * k for some integer k.
●
Examples:
○
7 ≡ 2 (mod 5) because 7 - 2 = 5, and 5 divides 5.
○
13 ≡ 1 (mod 6) because 13 - 1 = 12, and 6 divides 1.
○
25 ≡ 1 (mod 8) because 25 - 1 = 24, and 8 divides 24.
16
Even and Odd Numbers
▶ a and b are congruent modulo 2 (a ≡ b (mod 2)):
▶ This means 2|(a − b).
●
Case 1: If a and b are both even (2k, 2t), then
a − b = 2k − 2t = 2(k − t), so 2|(a − b).
●
Case 2: If a and b are both odd (2k + 1, 2t + 1), then
a − b = (2k + 1) − (2t + 1) = 2k − 2t = 2(k − t), so 2|(a − b).
●
Case 3: If one is even and one is odd, a − b is odd, and 2 ∤ (a − b).
17
Remainders 0, 1, or 2
●
When a and b are congruent modulo 3, i.e., a ≡ b (mod 3):
○
This means 3|(a − b).
●
Case 1: Both a and b leave remainder 0 (e.g., 3m, 3n).
●
Case 2: Both a and b leave remainder 1 (e.g., 3m + 1, 3n + 1).
●
Case 3: Both a and b leave remainder 2 (e.g., 3m + 2, 3n + 2).
Question: What can you say about the following cases?
a)
(3m + 3, 3n + 3)
b)
(3m + 4, 3n + 4)
c)
(3m + 5, 3n + 5)
18
Remainders 0, 1, or 2
●
When a and b are congruent modulo 3, i.e., a ≡ b (mod 3):
○
This means 3|(a − b).
●
Case 1: Both a and b leave remainder 0 (e.g., 3m, 3n).
●
Case 2: Both a and b leave remainder 1 (e.g., 3m + 1, 3n + 1).
●
Case 3: Both a and b leave remainder 2 (e.g., 3m + 2, 3n + 2).
Question: What can you say about the following cases?
a)
(3m + 3, 3n + 3) → Same as Case 1 → Remainder 0.
b)
(3m + 4, 3n + 4) → Same as Case 2 → Remainder 1.
c)
(3m + 5, 3n + 5) → Same as Case 3 → Remainder 2.
19
Simple Modulo Calculation
▶ When somebody asks 49 (mod 7), they are asking about the remainder of 49
divided by 7.
▶ We know 49 = 7 × 7 + 0.
▶ So, 49 ≡ 0 (mod 7).
20
Properties of Modular Arithmetic
●
Modular Addition:
(a + b) mod n = [(a mod n) + (b mod n)] mod n
Try out (17 + 23) mod 5
●
Modular Subtraction:
(a - b) mod n = [(a mod n) - (b mod n)] mod n
Try out (17 - 23) mod 5
●
Modular Multiplication:
(a x b) mod n = [(a mod n) x (b mod n)] mod n
Try out (17 x 23) mod 5
21
Properties of Modular Arithmetic
●
Modular Exponentiation:
22
Modular Exponentiation
●
It refers to finding the result of a number raised to a certain power and then
taking the remainder when divided by a modulus. In mathematical terms, it
calculates:
x = ab mod n
●
When the exponent b is large, calculating ab directly would result in an
extremely large number, potentially leading to overflow or inefficiency.
Modular exponentiation efficiently handles these large numbers by reducing
intermediate results modulo n
●
Note: ab mod n = [(a mod n)b] mod n
23
Example (Try it yourself)
●
Try to prove the following using modular multiplication property:
ab mod n = [(a mod n)b] mod n
Ans. ab mod n
= (a x a x a x …. x a) mod n ⇒ (here, a x a x a …. x a will be b times)
= [(a mod n) x (a mod n) x (a mod n) x (a mod n) x …. x (a mod n)] mod n ⇒ (using modular
multiplication property)
= [(a mod n)b] mod n
24
Modular Exponentiation In Programming
Python provides a built-in function pow(a, b, m) for modular exponentiation, which
is highly optimized.
25
If a ≡ b (mod n) and c ≡ d (mod n)
26
More Congruence Rules
27
Cancellation in Modular Arithmetic
▶ Question:
If ac ≡ bc (mod n), can we say a ≡ b (mod n)?
▶ Answer:
Yes/No? Justify your answer.
●
●
If Yes, then rethink.
If No, then what condition c must satisfy to be cancelled from the following
equation ac ≡ bc (mod n) ?
28
When Cancellation in Modular Arithmetic is Allowed?
[Think about it. Explore! Share the reason in lab.]
29
Sum of Factorials Modulo 12
▶ Problem: Find the remainder when 1! + 2! + 3! + · · · + 100! is divided by 12.
30
Sum of Factorials Modulo 12
31
Example
Check whether the given statement is True or False:
41 | (220 − 1), i.e., 220−1 ≡ 0 (mod 41)
32
Homework
1.
Find the remainders when 250 and 465 are divided by 7.
2.
Find (15 + 25 + 35 + 45 + · · · + 1005) (mod 4).
3.
Show that 53103 + 10353 is divisible by 39.
4.
Show that 111333 + 333111 is divisible by 7.
33
See You Guys
in Next
Session :)
Basic Arithmetic
Foundations (Part 4)
By- Dr. Ankur Gupta
CS01: Mathematics-I
1
Today’s Agenda
●
Modular Inverse
●
Divisibility rules
2
Quick Revision
●
𝑎 ≡ 𝑏 (mod 𝑛)
●
It also indicates that n divides (a - b) which means that (a - b) is a multiple
of n, i.e., (a - b) can be written as n * k for some integer k.
●
Examples:
○
47 ≡ 12 (mod 5)
○
13 ≡ 1 (mod 6)
○
129 ≡ 9 (mod 8)
3
Properties of Modular Arithmetic
●
Modular Addition:
(a + b) mod n = [(a mod n) + (b mod n)] mod n
●
Modular Subtraction:
(a - b) mod n = [(a mod n) - (b mod n)] mod n
●
Modular Multiplication:
(a x b) mod n = [(a mod n) x (b mod n)] mod n
4
Properties of Modular Arithmetic
●
Modular Exponentiation:
5
More Congruence Rules
6
Example
●
163 mod 7
=
1
●
233 mod 20
=
7
●
9272 mod 13
=
1
●
21063 mod 3
=
2
7
Modular Inverse
●
For integers 𝑎 and 𝑚 (with 𝑚>1), the modular inverse of 𝑎 modulo 𝑚 is an
integer 𝑥 such that a⋅x ≡ 1(mod m).
● In other words:
When you multiply 𝑎 with 𝑥, the product leaves remainder 1 when divided by 𝑚.
●
We denote it as a−1 (mod m) = x
8
Modular Inverse
Question:
What is the modular inverse of 3 modulo 7?
Solution:
We want 𝑥 such that:
𝑥 = 5 satisfies the above condition.
So, the modular inverse of 3 (mod 7) is 5.
9
Modular Inverse
Question:
What is the modular inverse of 4 modulo 8?
Solution:
Since 4 and 8 are not coprime, no modular
inverse exists for 4 (mod 8). 🚫
The modular inverse of 4 modulo 8 does not
exist.
10
Modular Inverse Existence Condition
●
The modular inverse of a (mod m) exists if and only if a and m are
coprime,i.e., gcd(a,m) = 1.
●
If gcd(a,m) ≠ 1, then no inverse exists.
[Think about it. Explore! Share the reason in lab.]
11
Modular Inverse
Let’s say the question is to find the modular inverse of a (mod m).
Thought Process:
● We will find x such that a.x ≡ 1 (mod m)
Think about the following:
● While checking for modular inverse why do we check for x values from 0 to
m-1 only?
Note: Every number outside 0 to m−1 is equivalent to one inside that range.
That’s why we only need to check m values, not infinitely many.
12
Divisibility Rules
13
Example
Your friend writes down a five-digit number, and then covers all digits except the
last digit, which is a 0, with his hand.
●
●
●
Is this number divisible by 2? Yes.
Is this number divisible by 4? Not possible to be certain.
Is this number divisible by 5? Yes.
14
Divisibility Rules
●
A number is divisible by 2 if its last digit is divisible by 2.
●
A number is divisible by 5 if its last digit is 0 or 5.
●
A number is divisible by 10 if its last digit is 0.
15
Divisibility of 4
●
What is divisibility rule of 4 ?
A number is divisible by 4 if last 2 digits of the number are divisible by 4.
But why ?
16
Let’s Decode the Magic Technique
●
Any number can be written as sum of hundreds, tens, and units.
○ Example: Check 234 is divisible by 4 or not
17
Determining if 234 is divisible by 4
There are 2 sets of 100 squares, 3 sets of 10 squares, and 4 sets of 1 square each.
●
●
●
Dividing 100 by 4 leaves a remainder of 0.
Dividing 10 by 4 leaves a remainder of 2.
Dividing 1 by 4 leaves a remainder of 1.
The sum of all these remainders is (2×0) + (3×2) + (4×1) = 10.
Dividing 10 by 4 leaves a remainder of 2, which corresponds to the remainder when 234 is
divided by 4.
Note: Since every power of 10 greater than 10 itself is divisible by 4, the remainder when a number
is divided by 4 is the same as the remainder when the last two digits of the number are divided by 4.
18
Revisiting Divisibility Rule of 2,5,10
19
The Magic Technique
●
To find out if a number n is divisible by another number m,
○
Do the division by m on each power of 10 in n separately, and
○
If there are remainders, add them together and determine whether
this sum is divisible by m.
20
Divisibility Rule of 3
Check Divisibility of 243 with 3?
243 = (2×100) + (4×10) + (3×1)
Sum of remainders = 2 + 4 + 3 = Sum of digits
21
Divisibility Rule of 9
Check Divisibility of 243 with 9?
243 = (2×100) + (4×10) + (3×1)
Sum of remainders = 2 + 4 + 3 = Sum of digits
22
See You Guys
in Next
Session :)
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )