120 likes | 138 Views
Today's lecture covers Number Theory exam topics including step sequences and pyramid plateau step properties. Learn about perfect squares, plateaus, and steps.
E N D
Applied Algorithms Lecture #8 Number Theory
Exam Today • Write Name in bluebook • Only 1 page of notes allowed • 90 minutes allocated for exam
The Step problem • Step from 7 to 21 • The sequence • 7, 8, 10, 12, 15, 18, 20, 21 • 1 2 2 3 3 2 1 • The deltas (size of the steps)
Note 7, 8, 10, 12, 15, 18, 20, 21 1 2 2 3 3 2 1 • Another problem where (end-start) 21-7 =14 will use the same deltas. • The deltas form an ascending, and then descending sequence.
Experiment 0 [] 1 [1] 2 [1,1] 3 [1,1,1] 4 [1,2,1] 5 [1,1,2,1] 6 [1,2,2,1] 7 [1,1,2,2,1] 8 [1,2,2,2,1] 9 [1,2,3,2,1] 10 [1,1,2,3,2,1] 11 [1,2,2,3,2,1] 12 [1,2,3,3,2,1] 13 [1,1,2,3,3,2,1] 14 [1,2,2,3,3,2,1] 15 [1,2,3,3,3,2,1] 16 [1,2,3,4,3,2,1] What’s the pattern here?
There are three kinds of deltas • [1,2,3,4,3,2,1] • [1,2,3,4,4,3,2,1] • [1,2,2,3,2,1] Pyramid Plateau step
Properties • Pyramids span a distance that is a perfect square (n2) • Plateaus span a distance expressed as n2+n • Steps span distances between these two
0 [] 1 [1] -- perfect square n=1 2 [1,1] 3 [1,1,1] 4 [1,2,1] -- perfect square n=2 5 [1,1,2,1] 6 [1,2,2,1] ** plateau n=2 7 [1,1,2,2,1] 8 [1,2,2,2,1] 9 [1,2,3,2,1] -- perfect square n=3 10 [1,1,2,3,2,1] 11 [1,2,2,3,2,1] 12 [1,2,3,3,2,1] ** plateua n=3 13 [1,1,2,3,3,2,1] 14 [1,2,2,3,3,2,1] 15 [1,2,3,3,3,2,1] 16 [1,2,3,4,3,2,1] -- perfect square n=4 17 [1,1,2,3,4,3,2,1] 18 [1,2,2,3,4,3,2,1] 19 [1,2,3,3,4,3,2,1] 20 [1,2,3,4,4,3,2,1] ** plateau n=4 21 [1,1,2,3,4,4,3,2,1] 22 [1,2,2,3,4,4,3,2,1] 23 [1,2,3,3,4,4,3,2,1] 24 [1,2,3,4,4,4,3,2,1] 25 [1,2,3,4,5,4,3,2,1] -- perfect square n=5 26 [1,1,2,3,4,5,4,3,2,1] 27 [1,2,2,3,4,5,4,3,2,1] 28 [1,2,3,3,4,5,4,3,2,1] 29 [1,2,3,4,4,5,4,3,2,1] 30 [1,2,3,4,5,5,4,3,2,1] ** plateau n=5 31 [1,1,2,3,4,5,5,4,3,2,1] 32 [1,2,2,3,4,5,5,4,3,2,1] 33 [1,2,3,3,4,5,5,4,3,2,1] 34 [1,2,3,4,4,5,5,4,3,2,1] 35 [1,2,3,4,5,5,5,4,3,2,1] 36 [1,2,3,4,5,6,5,4,3,2,1] -- perfect square n=6 Note how the length changes only at pyramid and plateau points.
Given distance d between endpoints • n = floor(sqrt d) • (n*n)==d we’re at a pyramid point • (n*n)+n ==d we’re at a plateau point • Otherwise we’re at a step point
length d | (n*n)==d = 2*n-1 | d<=(n*n)+n = 2*n | otherwise = 2*n + 1 where n = floor(sqrt d)
In Class Problems • Euclid Problem 7.6.3 • Page 159 of the text • We will write this together as a class
Today’s Assignments Read for next time Chapter 8 of the text. pp 167-188 Be prepared to answer questions in class next Friday from the reading. Programming assignment • 7.6.5 Summation of Four Primes • Page 161 • Write a solution Submit your solution (until you get it right) Hand in both your program, and the judge output. Those who volunteer to discuss their program get class participation points. Email me solutions before noon on Friday, May 6.