Prime Numbers Damian Gordon. Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number.

Slides:



Advertisements
Similar presentations
Prime Numbers and Prime Factorization
Advertisements

Prime Numbers and Prime Factorization
Prime Numbers and Prime Factorization. Factors Factors are the numbers you multiply together to get a product. For example, the product 24 has several.
Factors, Divisibility, & Prime / Composite numbers
Thinking Mathematically
Tutorial #6 PseudoCode (reprise)
Mathematical. Approach  Many of these problems read as brain teasers at first, but can be worked through in a logical way.  Just remember to rely on.
A number is divisible by another number if the quotient is a whole number with no remainder.
Flow Charting, Structured English and PseudoCode
Tutorial #7 Flowcharts (reprise) Program Design. Introduction We mentioned it already, that if we thing of an analyst as being analogous to an architect,
Flow Charting Damian Gordon. Introduction We mentioned it already, that if we thing of an analyst as being analogous to an architect, and a developer.
Factors Terminology: 3  4 =12
division algorithm Before we study divisibility, we must remember the division algorithm. r dividend = (divisor ⋅ quotient) + remainder.
BY MISS FARAH ADIBAH ADNAN IMK
A number that divides evenly into a larger number without a remainder Factor- Lesson 7 - Attachment A.
Loop Exercise 1 Suppose that you want to take out a loan for $10,000, with 18% APR, and you're willing to make payments of $1,200/month. How long will.
Python: Modularisation Damian Gordon. Modularisation Remember the prime checker program:
Selection: IF Statement Damian Gordon. adsdfsdsdsfsdfs dsdlkmfsdfmsdl kfsdmkfsldfmsk dddfsdsdfsd.
SWBAT to use divisibility rules for 2, 3, 4, 5, 6, 8, 9, and 10
Prime Numbers and Prime Factorization. Factors Factors are the numbers you multiply together to get a product. For example, the product 24 has several.
Objectives The student will be able to: 7A: Find the prime factorization of a number, the greatest common factor (GCF) for a set of monomials and polynomials.
5 Minute Check Find the prime factorization for each number
Iteration: WHILE Loop Damian Gordon. WHILE Loop Consider the problem of searching for an entry in a phone book with only SELECTION:
Factors
Searching Damian Gordon. Google PageRank Damian Gordon.
5.1 Divisibility. Natural Numbers The set of natural numbers or counting numbers is {1,2,3,4,5,6,…}
Dividing Polynomials & The Remainder Theorem. Dividing Polynomials When dividing a polynomial by a monomial, divide each term in the polynomial by the.
Factoring using GCF interpret parts of an expressions such as terms, factors, and coefficient.
Data Structures: Arrays Damian Gordon. Arrays Imagine we had to record the age of everyone in the class, we could do it declaring a variable for each.
Modularisation Damian Gordon. Modularisation Let’s imagine we had code as follows:
Prime Numbers and Prime Factorization. Factors Factors are the numbers you multiply together to get a product. For example, the product 24 has several.
Prime Numbers & Prime Factorization. Factors Factors are the numbers you multiply together to get a product. For example, the product 24 has several factors.
Divisibility Tests How can you tell quickly whether a number can be divided exactly by another?
A.4b Synthetic Division To thine own self be true, And it must follow, as the night the day, Thou canst not then be false to any man. -William Shakespeare.
Factors & Number Theory
CSCI 125 & 161 Lecture 12 Martin van Bommel. Prime Numbers Prime number is one whose only divisors are the number 1 and itself Therefore, number is prime.
Python: Structured Programming Damian Gordon. Structured Programming Remember the modularised version of the prime number checking program:
Prime and Composite Numbers A prime number is a natural number greater than 1 whose only factors are 1 and itself. The first few prime numbers are 2,
Recursion Damian Gordon. Recursion Recursion: Factorial Recursion is a feature of modularisation, when a module can call itself to complete a solution.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
Python: Iteration Damian Gordon. Python: Iteration We’ll consider four ways to do iteration: – The WHILE loop – The FOR loop – The DO loop – The LOOP.
Number Theory: Prime and Composite Numbers
Recursion Damian Gordon. Recursion Factorial Fibonacci Decimal to Binary conversion Travelling Salesman Problem Knight’s Tour.
Prime Numbers and Prime Factorization
Prime Numbers and Prime Factorization
3x + 2 6x3 - 5x2 – 12x – 4 2x2 – 3x – 2 6x3 + 4x2 -9x2 – 12x -9x2 – 6x
Factors
#2.5 Long Division.
Introduction to Python
Prime Numbers and Prime Factorization
Linked Lists Damian Gordon.
Prime Numbers.
Exercise 24 ÷ 2 12.
Prime Numbers and Prime Factorization
A number that divides evenly into a larger number without a remainder
Review Basic Math Divisibility tests Prime and Composite Numbers
Prime Numbers and Prime Factorization
Queues: Implemented using Arrays
Python: Algorithms Damian Gordon.
Prime Numbers and Prime Factorization
Prime Numbers and Prime Factorization
Structured Programming
Circular Queues: Implemented using Arrays
Some Common Issues: Common Algorithms
Prime Factorization FACTOR TREE.
Prime Numbers and Prime Factorization
Factor A factor of an integer is any integer that divides the given integer with no remainder.
Section 2-1 Factors.
Prime Numbers and Prime Factorization
Presentation transcript:

Prime Numbers Damian Gordon

Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number.

Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number. – What’s a prime number?

Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number. – What’s a prime number? – A number that’s only divisible by itself and 1, e.g. 7.

Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number. – What’s a prime number? – A number that’s only divisible by itself and 1, e.g. 7. – Or to put it another way, every number other than itself and 1 gives a remainder, e.g. For 7, if 6, 5, 4, 3, and 2 give a remainder then 7 is prime.

Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number. – What’s a prime number? – A number that’s only divisible by itself and 1, e.g. 7. – Or to put it another way, every number other than itself and 1 gives a remainder, e.g. For 7, if 6, 5, 4, 3, and 2 give a remainder then 7 is prime. – So all we need to do is divide 7 by all numbers less than it but greater than one, and if any of them have no remainder, we know it’s not prime.

Prime Numbers So, If the number is 7, as long as 6, 5, 4, 3, and 2 give a remainder, 7 is prime. If the number is 9, we know that 8, 7, 6, 5, and 4, all give remainders, but 3 does not give a remainder, it goes evenly into 9 so we can say 9 is not prime

Prime Numbers So remember, – if the number is 7, as long as 6, 5, 4, 3, and 2 give a remainder, 7 is prime. So, in general, – if the number is A, as long as A-1, A-2, A-3, A-4,... 2 give a remainder, A is prime.

Prime Numbers First Draft: PROGRAM CheckPrime: READ A; B <- A-1; WHILE (B != 1) DO {KEEP CHECKING IF A/B DIVIDES EVENLY} ENDWHILE; IF (ANY TIME THE DIVISION WAS EVEN) THEN Print “It is not prime”; ELSE Print “It is prime”; ENDIF; END.

Prime Numbers PROGRAM CheckPrime: Read A; B <- A - 1; IsPrime <- TRUE; WHILE (B != 1) DO IF (A/B gives no remainder) THEN IsPrime <- FALSE; ENDIF; B <- B – 1; ENDWHILE; IF (IsPrime = FALSE) THEN Print “Not Prime”; ELSE Print “Prime”; ENDIF; END.

etc.