Fun with Prime Numbers
Steve Litt writes "Fun
With Prime Numbers contains a series of prime number finding algorithms starting with the most brute force imaginable, and working up to a paged algorithm capable of finding the first 1,716,050,469 primes in an hour and a half on a commodity machine. There are faster algorithms on the net, but these algorithms are within the reach of mere mortals and are fully explained."
This article will be a prime target for bad jokes.
Mom says my
I got a 404...
"I'll have a Guinness, no wait, make that a Coors Light" -Grad student I work with, who shall remain anonymous...
"There are faster algorithms on the net, but these algorithms are within the reach of mere mortals and are fully explained."
So there are math gods out there?
Why not just save primes on a disk instead of recalculating them all the time?
EVER!!!
I'm number 1!!!!!
I understand that number sequences like Fibonacci manifest themselves in Nature and others like pi provide a fairly decent random number generation method. However, aside from the interesting property that they can't be divided by anything other than themselves and 1, I do not 'get' what is interesting or useful about prime numbers.
But then again, I haven't studied mathematics to any great extent beyond the multi-var calc and linear algebra back in high school. That was such a long time ago. Any math Geniuses out there want to clue is in on why primes are interesting?
I find that title so hard to appreciate, maybe I'm just not as big a geek as i thought.
Yes, this article is very informative and interesting, but I have one complaint:
The source code is often organized in confusing and/or excessively complicated ways. There are also non-standard typedefs.
> User assumes all risk and responsibility for any outcome.
I sure hope that doesn't include responsibility for brining his web server to its knees. I feel so guilty!
Fun, prime numbers, in the same sentence without some means of not connecting them in a positve light?
What manner of masochism is this page peddling in the name of fun?
"And we have seen and do testify that the Father sent the Son to be the Savior of the World" 1 John 4:14
This sounds like one of those topics in high school where if you sounded interested you were written a raincheck for an after school beating by the rugby team.
What's the first prime number?
Do Not Eat iPod Shuffle
Aren't most of the really large prime numbers only Mersenne primes?
Logic, macros, and more
If this gets you really excited, you know you are the truest form of nerd.
A slashdotter who didn't build his own computer is like a Jedi who didn't build his own lightsaber.
Reminds me, here's code to generate prime numbers: (earlier thread)
http://www.de.ioccc.org/2004/vik2.c
to cheat: http://www.de.ioccc.org/2004/vik2.hint
I didn't link them on purpose
And when we finally find a perfect algorithm, we can use it to...
uh
find more numbers.
So the macros knock the time down from 4.49 to 4.15 seconds -- less than a 10% reduction. In my opinion, that's not enough benefit to give up the robustness and typechecking of functions.
I never thought that I'd see a C programmer type something like that.
Can anyone point me towards some of the superior algorithms referred to in the summary?
see http://cr.yp.to/primegen.html
primegen is a small, fast library to generate prime numbers in order. It generates the 50847534 primes up to 1000000000 in just 8 seconds on a Pentium II-350; it prints them in decimal in just 35 seconds.
primegen can generate primes up to 1000000000000000, although it is not optimized for primes past 32 bits. It uses the Sieve of Atkin instead of the traditional Sieve of Eratosthenes.
What's the 1,716,050,470th prime?
BTW, the first bazillion prime numbers HAVE been calculated, so for those /.'ers with spare CPU cycles, consider something perhaps more worthwhile such as Folding@HOME
Hulk SMASH Celiac Disease
Read Penn Jillette's great explanation for details.
Vino, gyno, and techno -Bruce Sterling
Slashdot, the place in which godhood is defined by how many prime numbers you can find in an hour and a half.
read the bunni comic
Coralized link
My amazing wife - Artist, Author, Philosopher - Laurie M
So much for SSL!:)
Here's a nice, fun little resource for those interested in prime numbers. Actually, it's pretty large and exhaustive: The Prime Pages. Make sure to check out Prime Curios!; fascinating stuff.
Story posted at 10:30PM. Time now is...10:47PM. The site has been slashdotted. 17 minutes. I guess that's an ok time before the slashdot effect sets in.
A very fast segmented sieve (to find primes in an arbitrary range) can be found here, by Tomás Oliveira e Silva.
Of tangential interest is his Goldbach conjecture verification project. You can download his client and contribute to the project. He's shooting for 10^18...
djb:
see http://cr.yp.to/primegen.html
primegen is a small, fast library to generate prime numbers in order. It generates the 50847534 primes up to 1000000000 in just 8 seconds on a Pentium II-350; it prints them in decimal in just 35 seconds.
primegen can generate primes up to 1000000000000000, although it is not optimized for primes past 32 bits. It uses the Sieve of Atkin instead of the traditional Sieve of Eratosthenes.
There is a command in many unices and Linux called factor.
If you want to be a true geek you can try it on your friends phone numbers and find out if it is a prime.
Then, the next time you talk, inform them that their phone number is a prime, or tell them of their phone numbers prime factorization, and enjoy watching them think that you are a super geek and a super genius.
For even better effect, pretend to count in your head before you tell them this.
The Internet is full. Go Away!!!
...more like... Nerdular Nerdence!
...it'll do those poor people stuck in the Cube.
I'd have a personalized plate on my car, but "toxic bachelor" won't fit into 7 letters.
... can these "prime numbers" run Linux?
Oh, that works to make your friends think you are a geek.
On
The Internet is full. Go Away!!!
From the article:
... * 65537 + 2 = 2 * (3 * ... * 65537 + 1) ... * 65537 + 3 = 3 * (2* 4 * ... * 65537 + 1)
...
... * 65536 * 65537 + 65537 = 65537(65536!+1)
..., 65537! + 65537 are all nonprime (the first is divisible by 2, the second by 3, the thrid by 4 etc). Since we also know that there are infinitely many primes, there must be a prime greater than 65537! + 65537. The biggest prime less than 65537! + 2 and the least prime bigger than 65537! + 65537 are consecutive primes which are at least 65536 apart.
..., 6! + 5} ={722, 723, 724, 725, 726} are all nonprime, but also 24, 25, 26, 27, 28 are 5 consecutive nonprime numbers.
who can be sure that there aren't two consecutive primes somewhere that are more than 65536 apart
Let's recall elementary number theory:
65537! + 2 = 2 * 3 *
65537! + 3 = 2 * 3 *
65537! + 65537 = 2* 3 *
So the 65536 consecutive numbers 65537! +2 ,
Of course, 65537! is a massive number, which is unlikely to crop up in these calculations. There may be other sufficiently large gaps between primes among smaller numbers.
Consider, for instance, the method above applied with 5 in the place of 65536. We see that {6! +2,
For where we can expect large 'prime-free' gaps, I'll defer to any number theorist.
Naaaah. I'll let them get away with it by leaving this blatant advertising instead.
(Hint to the clue-challenged: I'm joking. I am not in favor of IP as a concept, which is why I give my feeble jokes away for free, which is about twice what they're worth)
i fear... i might end up taking a drill to my head.
Whats so great about prime numbers? why do they need really big ones? can't they just use small ones? ...why is there an expiry date on bottled water? why oh why!!?
Can someone tell me again what the point of this is?
Factor this!
Viva Guatemala!
gay fp
w00t fr1st p0st!!! ;-)
Seriously though, the article doesn't use anything more complicated than the Sieve of Eratosthenes to work out prime numbers - it just writes a list of prime numbers up to n to a file, then uses that to figure out a list of primes up to n^2.
It's still quite cool, though. It checks 40 billion numbers in 3 hours - about 10000 seconds. That means 4 million clock cycles per number - which does seem to be fairly high, considering that half of those numbers will be even, a further sixth will be divisible by 3 (and odd), and so on. None of them will have a factor of more than 200000.
I wonder if fiddling around with bit patterns (taking out sequences of the number being tested against in the number being tested) would speed it up.
Does this really have any practical use? I remember DeCSS had something to do with decoding using prime numbers, but other than something like that, what will this actually achieve?
is my uid a prime number?? Oh wait....
what's the deal with finding the last or the biggest prime number? is it useful for something or what?
The linked .txt file is 7.1 MB, so it probably will take a while. The Google cache doesn't do the number justice. In fact, the cached number is divisible by 2...
If you're interested in running a distributed.net-like application with the chance to make some money using your CPU cycles to help find prime numbers, have a look at here. They give some good information about what prime numbers are, and what they're good for.
BeauHD. Worst editor since kdawson.
first post already!
cool
Either he's got a good server, or no one cared enough to look.
That's the ultimate insult -- making the front page of Slashdot, then *not* getting Slashdotted as a result...
-- stream of did I lock the front door consciousness
i have fun with your mom
1 is prime is it not?
I'm dating myself, but this reminds me of a computer science class (late 80s) where we used the Sieve of Eratosthenes to find primes. Had fun writing it on a VAX 8550 and then porting it to our lightning fast 80286 10MHz PCs...
s .h tml
http://mathworld.wolfram.com/SieveofEratosthene
hrmmmmm...interesting
Prime number generating and factoring programs have been one of my favorite 'kick the tires' tests for any new hardware. This goes way back to early times for me, back to when the only programmable device I could own (back in the 70's) was a programmable calculator. It's still something I throw together and run on about anything programmable I acquire. I've even thrown a routine together for my ancient Tandy PC-8 Pocket Computer. Not sure what speed it runs, but it's gotta be a small fraction of a megahertz. Not sure how the old TI SR-56 I started out with in 1977 would rate.
"What's the frequency Kenneth?"
Here is way more than you could probably want to know about primes. And I would add an uninteresting linguistic fact: Primo is the Spanish word for prime, which also means 'cousin', which also means 'naive', in a pretty widespread slang over here. That gives any high school math class a new twist :).
To do list for Windows
31337 is still prime.
How about when you're on the vintage mainframe level in Tron 2.0, ask some random program to calculate the seventh even prime number. When he segfaults, you get access to the directory containing Tron Legacy. Just don't ask yourself that question...
The author was definately imagining a beowulf cluster of prime number solvers.
Try actually thinking for yourself. It's quite refreshing.
This site probably won't last long, heres google's cache:w w.troubleshooters.com/codecorn/primenumbers/primen umbers.htm+&hl=en/
http://66.102.7.104/search?q=cache:3EXdsF5PiA4J:w
One day, we were hanging around in the ACM chapter office and someone was working on his PC. He asked how big he should make some partition because he just didn't feel like deciding, and someone said "How about a nice, even 5 gigs?"
... it's prime!"
After a few seconds had passed, somebody pointed out: "Wait...not only is 5 not even
psot
that he's looking for work.
i need to one up him so I can get away with plugging myself..
I was looking at the article, and I realised there was no mention for fermat's or millar rabin, which I thought was used for bigger scale applications.
But anyways, great article, although the code could be better in terms of style, its just me though i think.
My java implementation of the sieve finds the first primes in 10 million in under a second. Just found that interesting, same cpu as this guy but Mobile athlon (its my laptop) and has only 512 ram but for such a low range this shouldnt matter.
Thanks to whoever found this article. It was a "prime" find!
*chortle*
Now, who can forget the Prime Number Shitting Bear?
Everybody knows that calculating Pi is a better way to get chicks.
The primes generated using these algorithms are officially sanctioned by the NSA.
Happy encrypting, everyone.
And quit trying to overload Echelon, would ya?
aparently no one cares.
I've always thought it was cool to see different ways of doing things with programming.
Have a look here for a pretty tight upper bound on the number of primes up to a given number. Using an array, instead of a linked list, would probably lead to a small speed improvement on his code.
He could also use an std::vector from C++. As far as I can tell it's pretty easy to resize.
Join the NFSNET. Our prime goal is making little numbers out of big ones. http://www.nfsnet.org/
first post
encryption.
"It is not how things are in the world that is mystical, but that it exists." -Ludwig Wittgenstein
Is it these kind of algorithms that the makers of benchmark tools to stresstest cpu's? I'm assuming thats what Prime95 does since its called PRIME but I could be wrong and I might be. Anybody to correct me?
first post yall
vcic for life
startspam: If you want to buy primenumbers.com just send an email to info at 013 dot com. Cheers! endspam
frist psot?
Or, better yet, UT2004.
(Am I trolling? Just being sarcastic? Genuinely irritated by his lame coding style? Who knows!)
FP Bitches.
"One is the loneliest number that you'll ever do Two can be as bad as one, its the loneliest number since the number one"
"Have you ever thought about just turning off the TV, sitting down with your kids, and hitting them?"
My Holloween Costume!
I marked up a sweatshirt with a bunch of random prime numbers and, dum roll please, I WAS the 'Indivisible Man'.
Tada.
~tel0p
take a class in abtract algebra, generally the first class in higher, proof-oriented mathematics. Primes have strong relevance in group theory (which is in itself relevant to quantum mechanics), which leads to rings and fields (widely applicable in linear algebra, analysis), which leads to other advanced topics.
The Prime Number Shitting Bear. Watching a console window spit out prime numbers might do it for the geeks, but everyone can loves the prime number shitting bear.
Is the IOCCC entry one of the methods mentioned? :-p
Karma: It's all a bunch of tree-huggin' hippy crap!
The bit shift and bit mask values should be compile-time constants, e.g.: , : : : :
enum {
bytesPerInt = sizeof(unsigned)*8
bpiShift =(bytesPerInt==16 ? 4
bytesPerInt==32 ? 5
bytesPerInt==64 ? 6
bytesPerInt==128 ? 7
0/*->error*/ ),
bpiMask = (1<<bpiShift)-1
};
This will allow the compiler to generate more efficient/hardcoded masking & shifting instructions.
Next, it is pointless to store/test even numbers inside the array - you could nearly double speed here, and simply shift down the array indices by one extra bit.
Similarly, it is easy enough to avoid testing multiples of 3, by alternating between increments of 2 and 4 times the prime number being tested.
Of course, much more can be done (even while maintaining the current level of code portability), but these are the obvious steps I would take to speed-up the presented bit-array method (paged or not).
So I presume that the Brits are either jealous of American programmers or are retarded.
One does not preclude the other, of course.
From the deluge of comments this story has had, perhaps there's been too much fun goin' down...
Dada Mail - Program, Art Project or Absurdity?
Big O(n/2) is equivalent to Big O(n), so with your suggestion of removing all even numbers results in no speed up at all.
For those who scoff at this kind of stuff, we have to keep in mind that it's this sort of tinkering that results in some of the most amazingly useful and interesting stuff later.
I have one lament, which is that his code formatting (indenting) got munged, making it really hard to read the code. I'm really tired, so I just couldn't manage to read through all the C code. I hope he fixes the page so that I can read it more easily later.
I'm pretty rusty on programming and haven't done anything in years, but I'm wondering: is there anything new in the way of some sort of a structure that meets arrays and linked lists halfway? Sort of a dynamic array with the flexibility of linked lists and ease of arrays?
As mentioned, DJB's primegen is much faster. Even his Sieve of Eratosthenes implementation will do the primes up to a billion in 1.38 seconds on a 2.4 GHz P4, which is roughly 100x faster than this guy's "all primes below 100 million in less than 13 seconds" (although he doesn't specify on what machine). There's no reason to be using huge memory "pages," you can sieve up to N with any size interval you want (like say, the size of your L1 d-cache) using only Sqrt(N) memory for the primes up to Sqrt(N).
I am really surprised the author never mentions wheel factorization. It makes the task even easier.
Here is my favorite program. It includes a 64-bit version.
...spike
Ewwwwww, coconut...
...and I'm going to list a few improvements here that I think the author missed.
In one of the early programs, the author had the idea of skipping all even numbers, which are of course divisible by 2. In the next program he found out how he could skip numbers divisible by 3. One can make a systematic method out of that -- in the literature it's known as adding a wheel to the sieve of Erathostenes. Thing is, he implemented the sieve of Erathostenes foregoing this improvement he had implemented earlier. This leads to a big improvement: when using a wheel with the first four primes 2,3,5,7, there are only 48 residue classes out of 210 = 2*3*5*7 possible that are not divisible by any of these four primes. In practice this means that, for each 210 numbers you'd consider, the sieve would only need be applied in 48 of them. That's a gain of 4.375. One can make a gain of nearly 5 using a wheel of the first five primes, but it begins to get complicated.
Another improvement would be to make the program cache-friendly. He sort of did this, down one level of the memory hierarchy, by paging the data to disk -- now he only needed to realize that, just as memory is much faster than disk, cache memory is faster than main memory. I've developed a sieve employing this optimization and it pays off indeed. This is considered a basic technique in the realm of high-performance computing. (The NFSNET, see my sig, uses a sieve including this and other optimizations, for instance).
I might get flamed for this, but he should consider assembly programming. There aren't many applications where assembly will pay off so handsomely as this one, and the `core' of the sieve is very small, so only a few lines of assembly are needed. Vector integer instructions, such as MMX and the integer instructions of SSE2, can be employed to very good advantage here. My sieve program also included this, and it gives a real nice boost -- and only about 25 lines of assembly were used, the rest was C.
Lastly there's the issue of representing the output. He stored the primes on disk by writing their values. A little compression can be realized in this representation: for instance he's printing out the primes in decimal, while hexadecimal would be more space-efficient. And instead of printing out the ASCII characters from 0 to 9, A to F, he could use a binary representation and read them through an hex dump -- that saves half the space, as a byte is used to store two hexadecimal digits instead of one.
A perfectly good representation that could save a lot of space (8 times, to be precise) would be a bitmap, which he used on some of his programs. That's where you represent primality or lack of it by setting and clearing bits of an integer. It's pretty easy to determine a prime from a bitmap value, so this representation is just as good as the previous one. One could also use the wheel idea I explained before to save even more space: a concrete example would be that for each block of 210 numbers, one needs only bitmaps for 48 of them, as the rest are divisible by the first four primes. In this example a savings of 4.375 would be realized. Of course, all these ideas would require special readers programs, instead of just opening up the files in a text editor -- a small price to pay for such a large space savings.
But in case only sequential reading of the primes is desired, there is an even more efficient representation: just write out the prime gaps, i.e. the difference between consecutive primes. One bit can be saved by realizing that, other than 3 - 2, all prime gaps are even, so one can just store the prime gap divided by two. One could really nitpick and point out that 0 is an impossible prime gap, so one could subtract two from all gaps, but this gain is too small to be worth the hassle. According to Thomas Nicely (incidentally the guy who discovered the bug on the Pentium FPU during his studies on computational number theory), one could store the prime gaps of all
Join the NFSNET. Our prime goal is making little numbers out of big ones. http://www.nfsnet.org/
From here:
"Dear Evan: You may have already addressed this question, but I'd like to hear your opinion on one of my pet peeves. "To beg the question" does not mean anything even remotely similar to "to lead us inexorably to the question" or "causes us inevitably to ask the question." It means to assume an answer to an unstated question or premise. It was used correctly on a recent episode of "The X-Files" when Mulder and Scully were discussing what was purported to be an alien autopsy. The exchange goes something like this: "Mulder: What is that green fluid? Scully: Blood? Mulder: It's widely held that aliens don't have blood. It must some unknown autopsy apparatus. Scully: That begs the question that it's an autopsy, let alone one of an alien." See what I mean? -- Michael Raynor, via the Internet.
I say, your question gives me a marvelous idea. Would you mind writing this column while I nip off to the Bahamas for a month or two? It's really not hard at all -- you just look things up in four or five hundred dictionaries and pick the answer that seems most plausible. I've found that you can usually fill the first paragraph of your answer with silly banter, anyway.
Regarding your question, I do see what you mean. Incidentally, if people on television have begun using proper English, perhaps it's time for me to buy a TV. I have never seen "The X Files," but if what you describe is typical dialog, the scriptwriters must be holding an English major hostage -- they did indeed use "beg the question" correctly. It does not mean "raises the question," or that the question itself begs like Oliver Twist ("Please, Sir, may I have an answer?"). It means to bypass or avoid an essential question, but to proceed as if it had already been answered. The Latin name for this sort of thing is "petitio principii," by the way. In your example, to discuss the color of alien blood sidesteps (or "begs") the rather essential question of whether there are such things as aliens in the first place. Similarly, my offer to you "begs the question" of whether I can afford to go to the Bahamas for a month or two in the first place, which I can't, so I'm afraid the deal's off."
Time to get back to earning my $100,000 ticket to a lifetime of burger-flipping.
First, what's with the %ull format specifier in sprintf - is that even a valid format specifier?
Next, why subtract 2 from your buffer length when printing?
Finally, why bother with the "printprime" and sprintf function altogether - is there anything wrong with:Okay, this is kind of nitpicking, but I'm clearly missing something obvious here...
- Any Day above Ground is a good Day (Michael Rich, 1997)
Mainstream language usage determines the accepted meanings of words and phrases. This phrase is used incorrectly by millions of people (myself included). It is only a matter of time before the dictionary is updated. It's nice to see the X-Files mentioned, though. Such a great show (until season 7). Now it's just a filler for late nite slots on TNT. So sad.
Sincerely,
John Ashcroft (retired)
Hey none of you buggers would be anywhere without me! Without Zero, 10000 would just be 1-nothing-nothing-nothing-nothing. w00t!
Cool, that's the Prime time, baby! Yeehaw, your mom's a virgin.....oh...wait...
Excuse my ignorance, but what are extremely large primes used for?
Obviously to get a date with a hot chic so you can impress her with the math you know.
Take the cheese to sickbay, the doctor should see it as soon as possible - B'Elanna Torres, "Learning Curve"
Actually the code indentation problem is only present on my system in the OS X Safari browser... I tried Camino, and presto, it works right!
Even IE for Mac seems to do the indentation 'right' (But not pronounced enough).
Safari seems to do the layout totally haphazardly! The code is really unreadable... I was sure more people here would have noted that, but seemingly not many people use Safari.
Tip: Use Camino... it's really a lot faster and seems to work for more sites.
Shouldn't any decent optimizing compiler (gcc?) inline those commonly-called functions anyway?
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
"There are faster algorithms on the net, but these algorithms are within the reach of mere mortals and are fully explained."
Well jeebus Mildred!!
convert this to c# for me?
As a few people have enquired but nobody's answered . . . Prime numbers are useful for a few things but the one I know a bit about is encryption and digital signatures. Most modern day (digital) encryption algorithms use large prime numbers because of their various properties. By using modular arithmetic and prime numbers as keys, strong encryptions can be formed because prime numbers are very hard to factorise. (They use large numbers don't forget) You'll probably find that a lot of the digital encryptions and signatures that you use on your computer either by compressing (and encrypting) files, using https, certificates of authority as well as others will use prime number theory as part of their algorithm. Hope this was some help.
Prime numbers are used in public key encryption. This type of encryption relies on having a function that is easy to generate, but very difficult to reverse. Factorization of large numbers is exactly the function that is used in practice: the prime factors of a large number can easily be multiplied together to get an even larger number, but getting those prime factors back from the giant number is hard. In fact, as the giant number size increases linearly, the time to calculate the factors increases exponentially (using the best known algorithms).
But where is their beauty? Like was mentioned before, fibonacci shows up all over the place, pi is at the core of almost everything, and you can't take a look at anything without visualizing the Golden Mean.
The use of prime numbers in encryption is fine and dandy, but no more complex than using something simple like Blowfish which is essentially a one-time pad. A thing's application does not establish its beauty.
There was a post above that pointed to a pictograph of primes plotted in a spiral manner in which diagonal streaks were visible, but that seems a wee bit contrived. Primes seem to be an interesting property of numbers, but they do not seem to have a natural "manifestation" which would grant them beauty.
How to prove that all odd numbers are prime? Well, this problem has different solutions whether you are a:
usage: prime [-nV] [--quiet] [--silent] [--version] [-e script] --catenate --concatenate | c --create | d --diff --compare | r --append | t --list | u --update | x -extract --get [ --atime-preserve ] [ -b, --block-size N ] [ -B, --read-full-blocks ] [ -C, --directory DIR ] [--checkpoint ] [ -f, --file [HOSTNAME:]F ] [ --force-local ] [ -F, --info-script F --new-volume-script F ] [-G, --incremental ] [ -g, --listed-incremental F ] [ -h, --dereference ] [ -i, --ignore-zeros ] [ --ignore-failed-read ] [ -k, --keep-old-files ] [ -K, --starting-file F ] [ -l, --one-file-system ] [ -L, --tape-length N ] [ -m, --modification-time ] [ -M, --multi-volume ] [ -N, --after-date DATE, --newer DATE ] [ -o, --old-archive, --portability ] [ -O, --to-stdout ] [ -p, --same-permissions, --preserve-permissions ] [ -P, --absolute-paths ] [ --preserve ] [ -R, --record-number ] [ [-f script-file] [--expression=script] [--file=script-file] [file...]
prime: you must specify exactly one of the r, c, t, x, or d options
For more information, type "prime --help''
Segmentation fault, Core dumped.
Non-Linux Penguins ?
Here is some more fun with prime numbers: "Prime number shitting bear"
My quality social news site.com.
where prevprime returns the prime number <= x and nextprime returns the prime number >= x.
Let x = y
/. to figure out high school maths?
Multiply both sides by x:
x^2 = xy
Subtract y^2:
x^2 - y^2 = xy - y^2
Now we can factorise. The left side is done using the difference of two squares method, the right is a simple factorisation.
(x + y)(x - y) = y(x - y)
Now we can cancel out (x - y) i.e. divide both sides by this:
x + y = y
So if x = y, then x + y = 2y
Therefore:
2y = y
Give y an arbitary value, e.g. 1:
2 = 1
We can also set y to the power of 0 on both sides, also giving us
2 = 1
IANAM (I am not a mathematician, nor a great speller).
*Sanity note: Yes, there IS a flaw with this, how long will it take
Ok, i'm dumb... What good is knowing all these numbers???
If X is the new Y, and Y is "X is the new Y", solve for X.
...since says to me something about a forbidden 503, which is a prime number...
Your head a splode
the list of proofs is entitled "15 good reasons why Pure Mathematics is not taught to first year students."
Do you think they just mean arts students?!!
I'm sure we (i.e science students) had no problems with simple proofs of that nature in our first year pure maths subjects. (shrug)
a very very small number of large primes are Mersenne numbers, a very very small number of Mersenne numbers are prime. The point with the Mersenne numbers is that there are slightly more likely to be prime than a random large number and more importantly various mathematical tricks can be used to test a mersenne number for primality so they are quicker and easier to test than other numbers. These are the reasons why it is valid to say that most very large discovered primes are Mersenne numbers
To get a story at slashdot, of course.
...
Of course there are also some less important uses in programs like pgp or ssh
The Tao of math: The numbers you can count are not the real numbers.
this give obviously loves his own name very much. he uses it under *every* heading of the page..
"Fun" with "Prime Numbers"...cmon.
Slashdot:
www.eFax.com are spammers
This was the method I used in my first attempt to write a prime-number generator. I figured that any positive integer can be written as 6n, 6n+1, 6n+2, 6n+3, 6n+4 or 6n+5 where n is an integer; and furthermore, 6n, 6n+2 and 6n+4 are definitely even, while 6n+3 is definitely a multiple of three. So we only need to try 6n+1 and 6n+5 to see if they are primes. Also, the smallest prime factor of a non-prime number must be smaller than or equal to its square root; so you don't need to try every known prime for divisibility. Rather than do a square root, though, I squared the testing_factor and compared it with the prime_candidate. This is quicker for small prime_candidates; but, as the list of known primes {and thus testing_factors} grows, eventually the many multiplications will start to take longer than one square root evaluation. The crossover point actually is a system-by-system variable, since it depends on FPU performance.
..... } can be used, with very slight modification, as a sort of pre-sieve to eliminate things that are never going to be primes. For instance, looking at 30n+m, the "potential primes" are 30n+1, 30n+7, 30n+11, 30n+13, 30n+17, 30n+19, 30n+23 and 30n+29. {The primes smaller than 30 are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29; see how we simply have excluded everything which is a factor of 30, and included 1.} This list is good up to and including 209 {210 = 2 * 3 * 5 * 7} beyond which a new list will apply going something like 210n+1, 210n+11, 210n+13 ..... }
..... I think I might have to go and investigate .....
I subsequently worked out that any list of primes stopping one shy of a product of primes-so-far {6, 30, 210, 2310
Now this is beginning to look like a recursive process! Mind, we're getting longer and longer lists as the density of primes is getting smaller. Hmm
Je fume. Tu fumes. Nous fûmes!
http://jlcooke.ca/oclug/oprimes.c
Considering this occurred on an $800 commodity box running standard Mandrake 10 Linux with X running along with several other programs, I'm impressed.
Now if he had been running this on a Gentoo box with the -mspeedyprimecalcs flag...
+4 Informative for useless b1tching that isn't even correct?
Anybody have Java equivalents of these toy programs? I want to play in my native tongue.
"No matter where you go, there you are." -- Buckaroo Banzai
The algorithm still needs to be proved. Everything you need to know about the proposal is here.
Thanks for the interesting post. I wish there were more here like yours.
Patrick Doyle
I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
therefore the average information content of a single prime is obviously zero
From this it follows that the entire information content of all the primes is also zero, and anybody you may meet who thinks differently is merely the product of a deranged imagination.
- Give a man a fire and he's warm for a day, but set him on fire and he's warm for the rest of his life.
2+2=5
*For extremly large values of 2
Encryption: I may not agree with what you say, but I will defend your right to encrypt it...
There are a couple of easy improvements that can be made to Mr. Litt's program that I haven't seen mentioned.
When removing multiples of a new prime p, you don't need to test the even multiples of p, 2 already did that for you. This cuts your work in half.
Although less asymptotically beneficial, you can start with p^2 since the lower multiples of p have already been done in previous passes.
Check out my page below, with some non-guaranteed C code (compiles with Borland C++ 4.5 compiler). Using a full 8 bits to store prime gaps is rather inefficient, I do the same with almost half the number of bits. Since the vast majority of prime differences for primes less than 2^32 is less than 30, the differences can be stored as one of 30/2=15 numbers, and thus stored in four bits. I only use 15 values available in 4 bits to represent gaps from 2 to 30, and use the 16th for an escape code to mean the next 4 bits represents a gap value of 16 through 30 (or something like that - read the webpage, read the code documentation for whatever you can get out of it, I wrote this last century...).
t ml
http://mindspring.com/~benbradley/number_theory.h
I did a little more work since writing the webpage. Using four bits for gap storage appears to be the most compact up to 2^32, but not too far above that (I forget where), five-bit gaps become more compact. Writing code to pack and unpack five-bit gaps is, of course, left as an exercise for the student.
(btw [sneaking in metadiscussion], for some odd reason, I now have excellent karma, and my posts sart out at +2, which I can presumably prevent by checking the "No Karma Bonus" box. Why would I ever want to do that?)
Tag lost or not installed.