# Mathemagic (part the first)

This code snippet on calculating the first n Primes using the Python programming language fell into my RSS feed this morning. Very nice I thought, but then it occurred to me, what would be really fast would be to ask the internet. Or more specifically WolframAlpha. So I did: http://www.wolframalpha.com/input/?i=primes+less+than+1,000,000,000.

The first 20 of 50,847,324 prime numbers less that 109 are displayed in the internet equivalent of a blink of an eye.
One assumes that Mathematica is doing the sums in an efficient way so you get the benefit of expert algorithm knowledge *and* get right to the answer just by asking the obvious question “primes less than 10,000,000,0000″.
You also get to know how many of them there are, and if you want, you get a PDF listing them that you can use to wallpaper your room.
Prime numbers are very interesting. Wikipedia has a fairly detailed [introduction](http://en.wikipedia.org/wiki/Prime_number). Asking WolframAlpha about “[primes](http://www.wolframalpha.com/input/?i=primes)” gives you some basic information and examples of useful queries and there’s loads of information about Prime Numbers at the Mathematica [Mathworld website](http://mathworld.wolfram.com/PrimeNumber.html). Marcus du Sautoy talks about prime numbers (the “Atoms of Mathematics”) in [this video](http://people.maths.ox.ac.uk/dusautoy/flash/newleft.htm). There are also a number of ways of testing for finding prime numbers using [Prime Factorization](http://mathworld.wolfram.com/PrimeFactorization.html) and many efficient, and less efficient, ways of doing [Prime Factorization with a computer](http://mathworld.wolfram.com/PrimeFactorizationAlgorithms.html).
Incidentally, is the Python algorithm really the fastest way? What does *Mathematica* do? Answers, with proofs, in the comments! ## Author: cpjobling

Senior lecturer, College of Engineering, Swansea University

Posted on Categories Uncategorised