ShmoopTube

Where Monty Python meets your 10th grade teacher.

Search Thousands of Shmoop Videos


AP Computer Science Videos 113 videos

AP Computer Science 1.2 GridWorld Case Study and APIs
493 Views

AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?

AP Computer Science 1.4 Standard Algorithms
200 Views

AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?

AP Computer Science 2.3 Classes and Objects
191 Views

AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?

See All

AP Computer Science 3.5 Review of the Basics 178 Views


Share It!


Description:

Using the modulo in arithmetic.

Language:
English Language

Transcript

00:00

Sorry And here's your shmoop du jour brought to you

00:05

by supreme galactic leader module o All praise modelo All

00:13

right If mod took precedence over multiplication what would be

00:16

the result of while the following All right And here

00:22

the potential answers Okay well we already know that computer

00:32

science and math are joined at the hip and it

00:34

sounds like this is at its core a simple math

00:37

question The module o operator often represented by a percent

00:40

sign and shortened to mod will return the remainder of

00:44

those two values after division takes place So for example

00:47

the result of five mod too would be one since

00:50

that's the remainder you'd get from dividing two into five

00:55

in another case twelve mod for would return zero because

00:57

there'd be no remainder after dividing twelve by four just

01:00

be three and nothing left over So this question is

01:03

asking us to give mod precedence over multiplication This brings

01:06

us all the way back to the order of operations

01:08

Or pam does he remember pim das Rights are buddy

01:12

We're going to be using that here with ma djalo

01:14

ahead of multiplication in line So let's show that preference

01:18

by putting ma djalo operations in parentheses Well we'll start

01:21

with four mod five before divided by five zero with

01:25

a remainder of four so we'll get a four There

01:28

are ten mod seven would be three because ten divided

01:30

by seven is one with remainder of three Then we

01:32

have four month three which will be one of three

01:35

dozen foreign there's One left over and now we're left

01:37

with two times four divided by three times one Well

01:41

two times four eight of course and three times one

01:44

is three So now we're down A divided by three

01:47

eight five two three is too pulling six six six

01:50

six six forever like devil But all the possible answers

01:53

here our imagers So we'll convert this rather than rounding

01:56

up converting the repeating two point six six six two

01:58

an imager is this name is mouring The number that

02:02

will get two instead of three on Our answer is

02:05

c it's all well and good That module exists But

02:08

when would a person actually use it Well one real

02:11

world application of modular is to check if the number

02:14

is odd or even if ex mod to return zero

02:17

That means there was no remainder X is divisible by

02:20

two And therefore even if you were to expand that

02:23

idea outward and write a method to check any given

02:25

number to see if it's divisible by anything but one

02:28

and itself well you have built your first automated prime

02:31

number validator conquering mathematics and ushering in the reign of 00:02:35.275 --> [endTime] universal king module it's One a Divisive Later indeed

Related Videos

AP Computer Science 1.2 GridWorld Case Study and APIs
493 Views

AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?

AP Computer Science 1.4 Standard Algorithms
200 Views

AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?

AP Computer Science 2.3 Classes and Objects
191 Views

AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism
204 Views

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism. Which of the following will satisfy the conditional if statement for boo, str,...

AP Computer Science 4.2 Standard Algorithms
191 Views

AP Computer Science 4.2 Standard Algorithms. What kind of algorithm is the following?