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.

Slides:



Advertisements
Similar presentations
Equations and Inequalities Quick Review
Advertisements

Number Theory and the Real Number System
5 Minute Check Complete in your notebook.
Types of Number
Greatest Common Factor
Unit 171 Algorithms and Problem Solving - II Algorithm Efficiency Primality Testing Improved Primality Testing Sieve of Eratosthenes Primality Testing.
Least Common Multiple Objective: Finding Least Common Multiple (LCM)
The ABC’s of GCF and LCM.
Solving Equations: The Addition and Multiplication Properties
© 2007 by S - Squared, Inc. All Rights Reserved.
Highest Common Factors And Least common multiple
5 Minute Check Complete in your notebook.
Least Common Multiple (LCM)
{8, 16, 24, 32, …} are the multiples of 8 Common Multiples
Prime Factorization (Factor Trees) Greatest Common Factor
Solving Equations Medina1 With Decimal & Fractions.
Using Factor Trees to find the least common multiple (LCM)
1.4 Absolute Values Solving Absolute Value Equations By putting into one of 3 categories.
Number Theory.  A prime number is a natural number greater than 1 that has exactly two factors (or divisors), itself and 1.  Prime numbers less than.
Fractions: Simplification, Multiplication & Division Lesson 1e Next.
Factors
1.4 Solving Equations ●A variable is a letter which represents an unknown number. Any letter can be used as a variable. ●An algebraic expression contains.
5.1 Divisibility. Natural Numbers The set of natural numbers or counting numbers is {1,2,3,4,5,6,…}
Splitting the number Numbers, like everything else, can be split up into smaller parts. For atoms, these smaller parts are called quarks. For numbers,
5 Minute Check Complete on the back of your homework. Tell whether each number is divisible by 2,3,4,5,6,9, ,681.
Lesson 27Power Up EPage 188 Multiples Least Common Multiple Equivalent Division Problems.
Factors Prime Factors Multiples Common Factors and Highest Common Factor (HCF) Factors and Multiples Common Multiples and Lowest Common Multiple (LCM)
Chapter 1 Review 1.1 Division 1.2 Prime Factorization 1.3 Least Common Multiple (LCM) 1.4 Greatest Common Factor (GCF) 1.5 Problem Solving 1.6 Add and.
Exam Technique Read the question Highlight the important information! Read the question again Then answer the question Mark a Minute.
One-Step Equations I can show that solving an equation leads to finding the value that makes the equation true.
Integers Objectives: C Grade Recognise Prime Numbers
Slide Copyright © 2009 Pearson Education, Inc. Unit 1 Number Theory MM-150 SURVEY OF MATHEMATICS – Jody Harris.
Copyright©amberpasillas2010. Parts of a Fraction 3 4 = the number of parts = the total number of parts that equal a whole copyright©amberpasillas2010.
5 Minute Check Determine the missing digit to make the statement true. Complete on the back of your homework. 1. 6, ?59 is divisible by 3.   2.
Dear Power point User, This power point will be best viewed as a slideshow. At the top of the page click on slideshow, then click from the beginning.
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.
 What is the square root of a number? What is the square root of a number?  What is estimation? What is estimation?  How to find the square root.
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.
(c) University of Washington20c-1 CSC 143 Binary Search Trees.
 Scientific notation is simply a method for expressing, and working with, very large or very small numbers. It is a short hand method for writing numbers,
See if you know enough about numbers and their properties. CLICK HERE TO START.
Objective - To find the Least Common Multiple (LCM) of numerical and variable expressions and use it to compare and order fractions. Smallest number that.
Factors
Factors and Multiples.
Exponents and Order of Operations
Number Theory and the Real Number System
Number Theory and the Real Number System
Solving 1-Step Integer Equations
Solving Equations by 2-1 Adding or Subtracting Warm Up
Summer Packet Review Algebra 2.
Fractions Adding Unlike Denominators
PRIME FACTORS.
9 x 14 9 x 12 Calculate the value of the following: 1 4 × 12 =
Coding Concepts (Sub- Programs)
EQ: How do I solve an equation in one variable?
Solving Two-Step Equations Lesson 2-2 Learning goal.
SEQUENCES WHAT IS A SEQUENCE?
Fractions Adding Unlike Denominators
Solving Equations Finding Your Balance
Fractions Adding and Subtracting Unlike Denominators
Two step equation Operations
Cube Root-Least number
Square root Least number Multiply & Divide.
CSC 143 Binary Search Trees.
Starter: There are 25 prime numbers under 100.
Least common multiple of three numbers
Solving Equations by 2-1 Adding or Subtracting Warm Up
Dear Power point User, This power point will be best viewed as a slideshow. At the top of the page click on slideshow, then click from the beginning.
Subtract unlike rational numbers
Presentation transcript:

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 the rules of mathematics to develop an approach, and then to carefully translate that idea into code.

Example  Given two numbers m and n, write a method to return the first number r that is divisible by both (e.g., the least common multiple).

hints  What does it mean for r to be divisible by m and n?  It means that all the primes in m must go into r, and all primes in n must be in r.  What if m and n have primes in common?  For example, if m is divisible by 3^5 and n is divisible by 3^7, what does this mean about r?  It means r must be divisible by 3^7.  The Rule  For each prime p such that p^a \ m (e.g., m is divisible by p^a) and p^b \ n, r must be divisible by p^max(a, b).

Find the LCM of these sets of numbers.  3, 9, 21 Solution: List the prime factors of each. 3: 3 9: 3 × 3 21: 3 × 7 63 can be divided evenly by 3, 9, and 21.  12, 80 Solution: List the prime factors of each. 12: 2 × 2 × 3 80: 2 × 2 × 2 × 2 × 5 = can be divided by both 12 and 80.

Algorithm

Prime  A number is prime if it is only divisible by 1 and itself. So for example 2, 3, 5, 79, 311 and 1931 are all prime, while 21 is not prime because it is divisible by 3 and 7.  To find if a number n is prime we could simply check if it divides any numbers below it.  We can use the modulus (%) operator to check for divisibility:

Solution  for (int i=2; i<n; i++)  if (n%i==0)  return false;  return true;  We can make this code run faster by noticing that we only need to check divisibility for values of i that are less or equal to the square root of n

Implementation  public boolean isPrime (int n) {  if (n<=1)  return false;  if (n==2)  return true;  if (n%2==0)  return false;  int m=Math.sqrt(n);  for (int i=3; i<=m; i+=2)  if (n%i==0)  return false;  return true;  }

Problem  Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7.

Hints

 3 * (previous number in list)  5 * (previous number in list)  7 * (previous number in list)  How would we find the next number in the list?  Well, we could multiply 3, 5 and 7 times each number in the list and find the smallest element that has not yet been added to our list.  This solution is O(n^2).  Not bad, but I think we can do better

Hints *33*53*7 55*35*55*7 77*37*57*7 Red: duplications 3*33*53*75*57*7 33*3*33*3*53*3*73*5*53*7*7 55*3*35*5*35*3*75*5*55*7*7 77*3*37*3*57*3*77*5*57*7*7

Hints  In our current algorithm, we’re doing 3*1, 3*3, 3*5, 3*7, 3*9, 3*15, 3*21, 3*25 …, and the same for 5 and 7.We’ve already done almost all this work before—why are we doing it again?  We can fix this by multiplying each number we add to our list by 3, 5, 7 and putting the results in one of the three first-in-first-out queues.  To look for the next “magic” number, we pick the smallest element in the three queues.

Solution