A few more experiments with factoring: 2.

advertisement
A few more experiments with factoring:
1. Factor 1965289 and 828301.
2. Write a program that generates a random prime with 8 digits. You should first run
the sieve of Eratosthenes on a sufficiently large number (think about how big this
actually needs to be). Then generate a random eight-digit number (you will need to
import the random function (use “from random import random”) Then random() will
give you a random number between 0 and 1, which you should modify into an eightdigit number). Use the sieve to determine whether it is prime.
Some modular arithmetic:
3. Write a function that takes three inputs a,b, and n and computes ab mod n. You
should use the method of successive squaring to make this run faster. If you’ve
written the program well, it should run significantly faster than python’s native
exponential function.
Download