<<

Math/CS 467 (Lesieutre) Homework 2 September 9, 2020

Submission instructions: Upload your solutions, minus the code, to Gradescope, like you did last week. Email your code to me as an attachment at [email protected], including the string HW2 in the subject line so I can filter them.

Problem 1. Both prime and perfect get more and more uncommon among larger and larger numbers. But just how uncommon are they?

a) Roughly how many perfect squares are there less than or equal to N? √ 2 For a positive√ k, notice that k is less than N if and only if k ≤ N. So there are about N possibilities for k. b) Are there likely to be more prime numbers or perfect squares less than 10100? Give an estimate of the of each. √ There are about 1010 = 1050 perfect squares. According to the theorem, there are about

10100 10100 π(10100) ≈ = = 1098 · log 10 = 2.3 · 1098. log(10100) 100 log 10

That’s a lot more primes than squares. (Note that the “log” in the prime number theorem is the natural log. If you use log10, you won’t get the right answer.)

Problem 2. Compute g = gcd(1661, 231). Find a and b so that 1661a + 231b = g. (You can do this by hand or on the computer; either submit the code or show your work.)

We do this using the Euclidean algorithm. At each step, we keep track of how to write ri as a combination of a and b.

1661 = 7 · 231 + 44 44 = (1) · 1661 + (−7) · 231 231 = 5 · 44 + 11 11 = 231 − 5 · 44 = 231 − 5 · ((1) · 1661 + (−7) · 231) = (36) · 231 + (−5) · 1661 44 = 4 · 11 + 0.

So 11 is the gcd, and 11 = 36 · 231 − 5 · 1661.

Problem 3. Implement the trial division algorithm for factorization in a programming lan- guage of your choice. (You do not need to write a program that will break a number down all the way to prime factors, though you can if you want. It’s enough to have it find one factor and stop.)

1 a) Choose a prime number, and ask your program to factor it. (There is a big list of primes at the end of the book, page 233.) What happens? Roughy how many factors does the trial division algorithm need to check before concluding that N is prime? What happens here will depend on exactly how you coded it. Maybe it just terminates√ without displaying any output. Trial division in the most naïve implementation will use N steps. If you were trickier, say only check odd factors, it could be less. b) With the help of your program, find the prime factorization of 123456789. If your program just finds one factor of a number and then terminates, you can manually plug both the factors back in to continue. Make sure you confirm that all of your factors are prime. Tell me what steps you took and what output the program gave. It’s 3 · 3 · 3607 · 3803. c) Find a factor of the number 225 + 1. Fermat suggested that this number might be prime, but Euler disproved this in 1732 (obviously, he did not have the benefit of a computer). You can do this by trial division and you will find that 641 is a factor. But imagine doing this without a computer! Euler was found a clever way to do it.

Problem 4. a) Roughly how many prime numbers should there be between 1,000,000 and 1,100,000? (Hint: how can you use the prime number theorem here?) What is the probability that a random number in this range is prime? The number of primes between these is approximately given by: 1100000 1000000 π(1100000) − π(1000000) ≈ − ≈ 79075 − 72382 = 6693. log 1100000 log 1000000

(The exact numbers are actually 85714 − 78498 = 7216. So we are pretty close.) The probability a number is prime we estimate as 6693 6693 = = 0.06693. 1100000 − 1000000 100000 So the chance a number is prime is a less than 7%. b) With the help of your program from Problem 3, choose 100 random numbers in this range. For each one, check whether it is prime. How many did you find? (Submission: output the list of numbers you generated, with a yes/no answer for the prime- ness of each. If you haven’t figured out how to copy program output over to Gradescope, you can copy over five numbers by hand, with an indication of whether they are prime.) You’d expect to get 6 or 7 primes out of a hundred. Maybe you got more, maybe you got less. If you got a lot more, you probably did something wrong. If you got none, you also probably did something wrong (the chance of getting no primes is less than a tenth of a percent).

2