You are on page 1of 25

The Mathematical Tourist

By Ivars Peterson
August 8, 2008

A New Formula for Generating Primes


http: www!maa!org mathtourist mathtourist"8"8"08!html

Some simple expressions can generate a surprisingly large number of primes, whole numbers that are evenly divisible only by themselves and 1. The remarkable formula x2 + x + 1, for example, yields an unbroken string of ! primes, starting at x " !. #nother simple, prime$rich formula, x2 + x + 1%, generates prime numbers for all integer values of x from ! through 1&. Searching for a polynomial formula that produces all primes, however, would be fruitless. 'athematicians proved years ago that no polynomial expression with integer coefficients has only prime values. (ut there are other possibilities. So people have continued to look for simple prime$generating functions, and )utgers graduate student #ri$ %owlan& has *ust found a new one. +n a paper published in the Journal of Integer Sequences, )owland defines his formula and proves that it generates only 1s and primes. ,(lending simplicity and mystery, -ric )owland.s formula is a delightful composition in the music of the primes, one everyone can en*oy,, 'effrey (hallit recently $ommente& on his ,%e$ursivity, blog. # professor at the /niversity of 0aterloo, Shallit is editor of the Journal of Integer Sequences. 1ere.s )owland.s recursive formula for generating primes, as presented by Shallit in his blog. 2efine a314 " %. 5or n greater than or e6ual to 2, set a3n4 " a3n 7 14 + gcd3n, a3n 7 144. 1ere ,gcd, means the greatest common divisor. 5or example, given that a314 " %, a324 " a314 + gcd32, %4 " % + 1 " 8. The prime generator is then a3n4 7 a3n 7 14. The resulting numbers are the so$called first differences of the original se6uence. 1ere %, 8, 1ere 1, 1, are the first 29 values of the a se6uence: ;, 1!, 1&, 18, 1;, 2!, 21, 22, 99, 9<, 9%, 98, 9;, !, 1, 2, 9, are the first differences of these values: 1, &, 9, 1, 1, 1, 1, 11, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 29

, &, <, <;

+gnoring the 1s, we find that )owland.s formula generates the primes &, 9, 11, 9 3again4, and 29. +f we continue the process and remove duplicates, the formula generates the prime se6uence &, 9, 11, 29, %, 1!1, %, 19, 299, <%, ; 1, 188;, 9%%;, %&&;, 1&191, &9, 9!929, . . .

)owland &es$ri)es his formula in the ,A New *in& of ($ien$e, blog. 1e notes that the formula originated in 2!!9 at the N*( summer s$hool, where participants discover and explore computational systems that exhibit ,interesting, behavior. ,This was a surprising discovery, since previously there was no known reliable prime$generating formula that wasn.t expressly engineered for this purpose,, )owland said. )owland went on to prove mathematically that this recurrence produces only 1s and primes. 1e has created a +athemati$a &emonstration for exploring the recurrence. )owland.s formula is unlikely to lead to more efficient ways of generating large primes, a crucial operation in cryptography. 1is formula produces the prime p only after first generating 3p 7 94=2 1s. ,So it takes a really long time to generate a large prime,, Shallit said. )owland ,has a method for skipping over those useless 1s, but doing so essentially re6uires an independent test for primality., #re there other formula.s like )owland.s> )ecently, 5rench mathematician (enoit ?loitre proved that by setting b314 " 1 and b3n4 " b3n 7 14 + lcm3n, b3n 7 144 for n greater than or e6ual to 2, b3n4=b3n 7 14 7 1 is either 1 or prime. 'any other 6uestions remain. +s there anything special about the choice of a314 " %> 2oes )owland.s formula eventually generate all odd primes> )owland suspects that it does, but there.s much more to learn.

http://recursed.blogspot.com/2008/07/rutgers-graduate-student-findsnew.html

Sunday, July 20, 2008

%utgers Gra&uate (tu&ent Fin&s New Prime,Generating Formula


Studying prime numbers is like playing the guitar. No, really, let me explain. The guitar is a simple instrument: six strings, some frets, a sound hole. You strum with the right hand, and form chords with the left. What could be simpler !ny reasonably coordinated person can learn to play a simple song, such as "#eart of $old", passably in a few hours. %n the same way, the prime numbers ha&e a simple definition: the integers greater than ' that are di&isible only by themsel&es and '. !ny reasonably intelligent person can learn to test a small number for primality, or understand (uclid)s proof that there are infinitely many prime numbers, in a short amount of time.

Yet the guitar is also fiendishly difficult. Those studying classical guitar know well how some pieces take hundreds of hours to master. Techni*ues such as tremolo might take years, especially if you start learning as an adult. %n the same way, the prime numbers contain within them enough subtlety that many problems remain unsol&ed after hundreds of years. $oldbach con+ectured in ',-. that e&ery e&en number greater than . is the sum of two primes, and today this con+ecture is still unsol&ed. /%t is known to hold for e&ery e&en number less than '0'1.2 !nd a proof of the Riemann hypothesis, which would ha&e extremely important conse*uences for the distribution of primes, will net you a million dollars from the Clay Mathematics Institute 33 probably more than you)ll get from appearing on American Idol. 4or a long time mathematicians ha&e sought a simple formula that would generate all the prime numbers, or e&en infinitely many distinct prime numbers. Some ha&e e&en gone so far as to claim that no such formula exists 33 a statement of &ery *uestionable &eracity that depends entirely on one)s definition of "formula". %f you define formula to mean "polynomial with integer coefficients", then it)s not hard /and % lea&e it as a challenge to the reader2 to pro&e that no such polynomial can generate only primes, other than the tri&ial example of a constant polynomial. (uler)s polynomial x. 5 x 5 -' comes close: it generates primes for x 6 0, ', ., ..., 78, but fails at x 6 -0. ! slight &ariation, though, leads to a genuine prime3generating polynomial. %t is a conse*uence of the 9a&is3:atiyase&ich3;utnam3 <obinson work on Hilbert's 10th problem that there exists a multi&ariate polynomial with integer coefficients that takes on only negati&e and prime &alues when integers are substituted for the &ariables, and e&ery prime is generated by some choice of the &ariables. %n '8,=, >ones, Sato, Wada, and Wiens actually wrote down such a polynomial. %t has .= &ariables.

!nother prime3generating formula comes from a '8-, paper of W. #. :ills. :ills pro&ed that there exists a real number A such that ? A7n @ is a prime number for all integers n A '. #ere ? x @ is the greatest integer function, the greatest integer B x. Cnfortunately, nobody knows a good way to calculate A other than testing the numbers the formula is supposed to generate for primality, and then constructing A by working backwards. So many people ha&e worked on the prime numbers that it seems unlikely that there could be a simple prime3generating function that has been o&erlooked until now.

<utgers graduate student ric Ro!land has defied the odds, howe&er, and has found a new one. %n a paper +ust published in a +ournal % edit, the Journal of Integer Sequences, <owland defines his formula and pro&es it generates only ')s and primes. /' is generally not accepted as a prime number, for a "ariety o# reasons. 4or one thing, if ' were a prime, then positi&e integers would not ha&e a uni*ue factoriDation into primes.2 To be precise, % should say that the unusual property of the formula was originally con+ectured by a team led by :att 4rank at a mathematics summer school in .007 where <owland was attending, but it was not pro&ed until now. #ere is <owland)s formula. We define a/'2 6 ,, and for n A . we set a/n2 6 a/n3'2 5 gcd/n,a/n3'22. #ere "gcd" means the greatest common di&isor. So, for example, we find a/.2 6 a/'2 5 gcd/.,,2 6 1. The prime generator is then a/n2 3

a/n3'2, the so3called first differences of the original se*uence. 4or example, here are the first .7 &alues of the a se*uence: ,, 1, 8, '0, 'E, '1, '8, .0, .', .., 77, 7=, 7,, 71, 78, -0, -', -., -7, --, -E, -=, =8 and here are the first differences of these &alues: ', ', ', E, 7, ', ', ', ', '', 7, ', ', ', ', ', ', ', ', ', ', .7 %f we ignore the ')s, then, the <owland formula starts by generating the primes E, 7, '', 7 /again2, and .7. The reader can easily program up the formula and find lots more primes. <emo&ing duplicates, the first few are E, 7, '', .7, -,, '0', ,, '7, .77, -=,, 8-', '118, 7,,8, ,EE8, 'E'7', E7, 707.7, ... Why does it work The proof is too in&ol&ed to gi&e here, but it is not that difficult. The interested reader can go to Ro!land's paper for the details. <owland has been in&ol&ed with mathematics for some time. #e attended CF Santa FruD and graduated with highest honors in math in .007. Since then he has been a graduate student at <utgers Cni&ersity, studying with $oron %eilber&er. <owland describes himself as an "experimental mathematician", and uses the computer algebra system Mathematica for his experiments. <owland tells me that he tried to pro&e the formula from time to time o&er a four3 year period, but once the crucial insight was found, "% had an outline of the proof within a few days and all the details within a few weeks." !re there any other formulas like <owland)s !pparently yes. Genoit Floitre, a 4rench mathematician, recently pro&ed that if you set b/'2 6 ' and

b/n2 6 b/n3'2 5 lcm/n,b/n3'22 for n A ., then b/n2Hb/n3'23' is either ' or prime for all n A .. Will <owland)s formula lead to more efficient ways to generate large primes %f so, cryptographers would lo&e it. Gut it seems unlikely. !s <owland explains in his paper, his formula only produces the prime p after first generating /p372H. ')s, so it takes a really long time to generate a large prime. #e has a method for skipping o&er those useless ')s, but doing so essentially re*uires an independent test for primality. !re there still unsol&ed properties of <owland)s prime generator Yes. 4or example, is there anything special about the choice a/'2 6 , Ither choices, such as a/'2 6 1, always generate primes and ')s, but others, such as a/'2 6 E7., do not. /This choice generates 8 after less than .0 steps.2 #owe&er, <owland con+ectures that for each starting &alue of a/'2, there exists a point after which the first differences are always either ' or prime. <owland also doesn)t know if his formula e&entually generates all odd primes, although he belie&es it probably does. <owland has a number of other pro+ects in the works. #e told me, "%)m working on se&eral things, mostly trying to finish up a backlog of papers. Gut one newer pro+ect is putting bounds on the fre*uency of ')s in the 'ola(os(i !ord. !nother is something %)m not ready to fully di&ulge, but it has to do with &alues of the p3adic logarithm. ! longer term pro+ect of mine is extending what is known about the arithmetic of ;ascal)s triangle modulo m and, generally, additi&e cellular automata." What problem would <owland most like to sol&e "%)d really like to sol&e the )n*1 problem, because % think it would tell us something &ery interesting about representations of integers. 9i&iding by . in base . +ust means dropping the last 0, and mapping n 3J 7n5' in

base 7 +ust means appending '. The problem is that we don)t know how to get these two bases to talk to each other 33 and of course perhaps there isn)t a way 33 but a solution to the 7n5' problem might show us how to do this." Sol&ing the 7n5' problem would indeed be a great achie&ement. %n the meantime, howe&er, he can take pleasure in his prime formula. Glending simplicity and mystery, (ric <owland)s formula is a delightful composition in the music of the primes, one e&eryone can en+oy. Update, July 31 2008: <owland has his own post describing his disco&ery.
;osted by >effrey Shallit at 2+), -M Kabels: mathematics, primes
22 comments:

Shawn said... % wrote a *uick #askell program to generate this function: import Kist a'6, a n 6 /a n'2 5 /gcd n /a n'22 where n' 6 n 3 ' diffs ?@ 6 ?@ diffs /x:?@2 6 ?@ diffs /x:y:xs2 6 /y3x2 : diffs /y:xs2 primes 6 filter /J'2 L diffs L map a ?'..@ :aybe someone can optimiDe this....
1+12 -M

/nonymous said... 9oes it make sense not to be an "experimental mathematician" nowadays %f so, why
1+,) -M

/nonymous said... there are properties of interest that depend on something being infinite in a way that can)t be approximated with finite ob+ects or is too complex to be computed within reasonable time. if there is a way to test ones hypotheses it can make sense to )experiment). but often something works for )generic) ob+ects but not for all. for example almost all s*uare matrices are in&ertible, so if you test this hypothesis by generating s*uare matrices with uniformly random doubles in ?3','@ you will always /&ery high probability2 get an in&ertible matrix. so the experiment would not help much. as we know the answer already it)s ob&ious how to describe an experiment that shows that some s*uare matrices are not in&ertible, but if your problem is at the frontier of mathematical knowledge it can be less ob&ious. for some *uestions about integer se*uences experimenting is &ery useful, for the poincarM con+ecture not so much.
)+2) -M

4reakF(<S said...

%)&e been playing around with the problem in F /for performance2 and my program can calculate the differences of the first '0.000.000 numbers in the se*uence in about =.= seconds on my amd=-/.$#D2 3 best and worst run: gcc 3I7 3Wall 3o primes primes.c NN time .Hprimes JJ Hde&Hnull real 0m=.7.'s user 0m=..=1s sys 0m0.0-1s real 0m=.=81s user 0m=.=.1s sys 0m0.0E=s out of curiosity, % modified shawns haskell program /and assuming % didn)t break something in the meantime 3 this is the first time %)&e seen haskell2 this is it)s benchmarks 3 again, best and worst: ghc 3I 3o shawn primes.hs NN time .Hshawn JJ Hde&Hnull real 0m=.'=8s user 0m=.08=s sys 0m0.001s real 0m=.78-s user 0m=.7E.s sys 0m0.07.s 012 the haskell3&ersion only generates the first 25 numbers in the se*uence, as opposed to the F3&ersions 10.000.000 /might use less memory, though2

#ere is the haskell % used: primes.hs and here is the F3&ersion: primes.c !nyone up for optimiDing a bit more /% suggest looking into a more efficient gcd, perhaps with caching2
11+)3 /M

4reakF(<S said... Gy the way 3 %)&e also noticed that e&ery new prime p that is disco&ered that is higher than a/'2, seem to follow: p 6 a/p23a/p3'2 9unno if that was an ob&ious result, but if true, it would mean that the function cannot possibly return all primes 3 at least not for a single &alue of a/'2
12+20 -M

Slinky said... 4reakcers, ha&ing the cache and the recursi&e method seemed superfluous, as one only needs two numbers in the se*uence to create the next one. !lso, when doing so, one does not get limited by the memory with this. % changed the program not to ha&e the aforementioned things, and to skip all ')s, and also to put the two &alues to register. !lthough it)s not so much faster than your program, it doesn)t need a lot of memory. %f someone wants to play with it, grab it here.

)+18 -M

<yan $raham said... freakcers, slinky, http+44&ist.&ithub.com4125) Seems like the perfect scenario for testing out the shiny new gist.
,+,6 -M

Slinky said... % made a &ersion which uses the $NC :; multiple precision arithmetic library, +ust in case someone wants to run the program until "hell freeDes o&er" and see what kind of prime pops out... You need lib&mp. You can grab the updated program here. #a&e funO
7+0, -M

/my said... Ik, this is not music e&eryone can en+oy. %)m hopelessly lost. Gut %)m trying, if that counts for anythingO
3+2) -M

4reakF(<S said... #ah, % guess % should ha&e replied again sooner... The optimisation slinky mentions is actually in my current implementation /though % ha&e to admit, was introduced by a friend of mine, when % mentioned this problem to him2

% actually also considered gmp to allow for really large numbers, but taking into account the amount of time it takes to calculate the se*uence +ust up to '00.000.000 /well below any number that would re*uire gmp2 % figured it would +ust slow down the whole process for any reasonable application... What really needs impro&ement, is the gcd3algorithm 3 %)&e been reading up on "accelerated integer gcd", and more specifically "se*uential accelerated integer gcd" from the paper 8Impro"ements on the accelerated inte&er 9C$ al&orithm8 as it seam either that, or the parallel &ersion from same paper is more or less the best implementation around. % guess if anyone)s got a cluster lying around, the parallel &ersion along with gmp might come in handy, but until that, % recommend a&oiding gmp, sticking to at most unsigned long long int in F, and +ust optimiDing gcd, which is clearly the bottleneck at this point...
6+,5 -M

n00b said... Not sure about this... %)m new to this stuf... but would the gcd function be faster as an implementation of (uclid)s algorithm
11+75 -M

n00b said... unsigned int gcd/unsigned int u, unsigned int &2 P int t 6 0Q while /& O6 02 P

t 6 &Q & 6 u R &Q u 6 tQ S return tQ S Seems to be slightly faster though not significantly. L gcc 3I7 3Wall 3o primes primes.c NN time .Hprimes JJ Hde&Hnull real 0m'7.=,.s user 0m'7.E='s sys 0m0.070s L gcc 3I7 3Wall 3o primesTeuclid primesTeuclid.c NN time .HprimesTeuclid JJ Hde &Hnull real 0m'....-s user 0m'..'1=s sys 0m0.0=.s
1+23 /M

(rdosE= said... #mmm, paralleliDing is the next tempting possibility... %f you read the paper, an interesting point is that Stephen Wolfram was actually leading the summer school and we see the con&ergence with the notion of "experimental mathematics". So can anyone implement this using F!s
2+10 /M

4reakF(<S said... n00b, it depends on your platform, really... in theory, the binary one %)m using should be faster, but on some platforms (uclids algorithm outperforms it marginally /looks like yours is one such case2 Gut as % mentioned a couple of posts up, Se*uential /or ;arallel2 !ccelerated %nteger $F9 is /probably2 what we should be using 3 though % don)t know of any implementation of it %)&e not been able to find e&en an implementation of the "normal" !ccelerated %nteger $F9, though if anyone cares to read about it, here)s the paper: 2he accelerated inte&er 9C$ al&orithm
)+,1 -M

<yan $raham said... !ccording to some info on the $:; site, /http+44&mplib.or&4de"el42, there)s a &ery fast $F9 implementation planned for a future release. Should +ust be a drop3in replacement for the one in the current release, so maybe someone should gi&e it a try. !ccording to that page, it is significantly faster than the current one.
,+25 -M

4reakF(<S said... $ood catch <yan, the algorithm they)&e implemented is actually UexactlyU the "!ccelerated %nteger $F9 !lgorithm" % was talking about 3 % knew Venneth Weber had contributed some code to gmp, but from the paper it seemed it was only part of the algorithm 3 iirc, a bmod implementation... /% guess % was wrong2

%)&e been doing some number3crunching, and along with the realiDation that the accelerated algorithm doesn)t really offer a speed3up before there)s a E3bit difference in the siDe of n and a/n3'2, % think gmp will definitely be needed well before the new algorithm sa&es us time 3 %)m not actually too sure it will e&er happen 3 on a&erage this seems to hold: a/n2 W6 ..EUn, any cle&er arguments as to why this would or would not e&er cause a E /or more2 bit difference in siDes
6+7, -M

;seudonym said... Shawn: rowlandSe*uence 6 filter /H6 '2 L DipWith /32 /tail as2 as where as 6 as) , . as) an' n 6 an' : as) /an' 5 gcd n an'2 /n5'2 The two recursi&e calls are the main source of inefficiency in your code.
2+,1 /M

/nonymous said... % agree with ;seudonym, it can be calculated without e&en doing any recursion in c. The gcd function isn)t a big problem, the euclidean is fast enough for me. Gut the main code would look like: int main/&oid2 P unsigned int a,b,p,nQ a 6 ,Q for/n6.QnO6'0000000Qn552 P

b 6 a 5 gcd/n,a2Q printf/"Ri RiXn",n3',b3a2Q a 6 bQ S S which makes it twice as fast then the old one.
)+25 -M

/nonymous said... Fongrats to (ric on the paperO #ere is the formula in :athematica, which (ric uses: a?'@6,Q a?nT@ :6 a?n3'@ 5 $F9?n, a?n3'@@ %f you want to remember /memoiDe the &alues2 to speed it up: a?nT@ :6 a?n@ 6 a?n3'@ 5 $F9?n,a?n3'@@ %n?-@:6 !rray?a,.7@ Iut?-@6 P,,1,8,'0,'E,'1,'8,.0,.',..,77,7=, 7,,71,78,-0,-',-.,-7,--,-E,-=,=8S %n?E@:6 9ifferences?R@ Iut?E@6 P',',',E,7,',',',','',7,',',',',', ',',',',',.7S %n?=@:6 9eleteFases?R,'@ Iut?=@6 PE,7,'',7,.7S %n?,@:6 ;rimeYHZR

Iut?,@6 PTrue,True,True,True,TrueS #ere)s are the primes generated: %n?1@:6 4irstHZTally?9eleteFases? 9ifferences?!rray?a,'00000@@,'@@ Iut?1@6 PE,7,'',.7,-,,'0',,,'7,.77,-=,,8-', '118,7,,8,,EE8,'E'7',E7, 707.7,=0=-,S and in sorted order: %n?8@:6 Cnion?9eleteFases?9ifferences? !rray?a,'00000@@,'@@ Iut?8@6 P7,E,,,'','7,.7,-,,E7,'0',.77,-=,, 8-','118,7,,8,,EE8,'E'7',707.7, =0=-,S The formula can be seen as a "simple program" that generates an output known to be in some sense complicated, a point made &ery generally in Stephen Wolfram)s .00. book "! New Vind of Science". <ichard ;.
,+00 -M

/nonymous said... Through a uni*ue summation sie&ing algorithm it is possible to se*uentially produce all odd primes up too any stopping point of /n2 without using any pre&ious primes. Kikewise it is also possible to start with a large prime and continue with this se*uential list of

large primes up too any stopping point for /n2 without using any pre&ious primes in the process of generating these primes. #ere it is in ;ython code for all odd primes up too /n26 .0000. % am not sure if it will indent properly in this post because in pre&iew it shows no indents n6 3.Qn'6 3-Qn.6 3'Qn-6-QnE6'Qb'60Q+60 a6?0@U.000' data6?8,7,.,',7,.@ for i in range/len/data22: a'6data?i@ a'6a'5b'Qa?a'@6a'Qb'6a' a'6b'5nQa?a'@6a'Qb'6a' n6n5n' for x in range/.00002: i6nwhile iJ6.: a'6a'5i if a'[6.0000: a?a'@6a' i6i3' a'6a'5n if a'[6.0000: a?a'@6a' n-6n-5nEQn6n3nfor ii in range/'00002: i6.Uii5' if a?i@660 and iJ': print i,Q+6+5' print )Total odd primes 6),+ 333333333333333333333333333333333333333333333333333 ;rime print output 6 7,E,,,'',..'888, which is the last prime less than /n2 where n6.0000 and gi&es a total number of odd primes 6 ..='.

So odd primes do ha&e a pattern, complex as their pattern may be through summations and negations starting with /82. where this summation and negation ne&er produce an odd prime. %t is &ery slow but shows this complex pattern of the odd primes after the first summation of these = integers where no odd primes are produced at each point of the summation. 58575.5'575. Then continuing with the summations and negations below where also no odd primes are produced when this pattern emerges. 3. 5-575. 3= 5E5-575. 3'' 5=5E5-575. 3', 5,5=5E5-575. 3.515,5=5E5-575.

37. 58515,5=5E5-575. 3-' 5'05.. etc. The pattern for the negations is +ust the difference of 5- and 3. 6 = ,so the next negation is +ust 3= The next negation is the difference of 3= and 5E 6 '', so the next negation is 3''. and so on. The other groups of summations ha&e an ob&ious pattern which increments by one from the pre&ious group. !ll the odd integers produced from these summations and negations are composite and all the odd integers /not2 produced are primes except /'2. The problem is, many composites repeat one or more times which adds to the processing time. 9an
12+03 /M

/nonymous said... Kook up in google groups sci3math on +uly .-3.E for 33 "! prime $enerator that needs no pre&ious primes" will gi&e the correct indent for the ;ython program % posted here. 9an
6+76 /M

/nonymous said... This prime chain of 7.7, terms, '=,' of which are distinct, was found by means of a prime3producing generator closely akin to (ric <owland)s formula for an infinite chain: a/'2 6 ,, nJ', a/n2 6 a/n3'2 5 gcd/n,a/n3'2 . %t could be argued that neither one is a true prime chain since there is a &ast sea of ')s in3between each prime, and that mine is not really e&en a )formula) since it does not achie&e an infinite consecuti&e list, but % see these ob+ections as being more semantic than substantial in nature. % also belie&e that the entire set of primes occurring in the se*uence represented by x\. 3 x 5 ' will e&entually appear in the formula below,/about 'H. of all primes2 but this is yet to be pro&ed, and it is unclear due to e*uipment limitations if the extreme density of primes at the beginning of the se*uence continues indefinitely or breaks down at some point. Ket f/x2 :6 x\. 3 x 5 -', x 6 ', k 6 ., a 6 7 . <epeat indefinitely a two3step process: x :6 x 5 ', %f $F9/ x\. 3 x 5 -', /x3'2\. 3 /x 3 '2 5 -' 3 aU k 2 J', then k :6 k 5 'Q

The first .0 &alues of the se*uence that do not e*ual )') are: -,, ..,, ,', 7E8, ''7, E=7, ',7, 178, .E',''1,,7-,, '=0,, -=',.088,E87, .==7, ,-7, 7.88, 8'',-00, :any other &alues for the )a) &ariable abo&e, perhaps infinitely many, /but not all2 may be substituted in the formula and produce long initial prime chains. for a 6 7 : 7.7, consecuti&e primes, a 6 . : ,7= a 6 - : 1', a 6 E : 1E1 a 6 = : '=' a 6 , : ''E8 a 6 1 : ..' a 6 8 : .1a 6 '0 : '.,= etc. :any other e*uations, perhaps infinitely many, /but not all2 may be substituted for x\. 3 x 5 ' in the gi&en formula, or a more complicated de&elopment of that formula, with good results. (xample: f/x2:6 EUx\. 5 EUx 5 ', x 6 ', k 6 ., a 6 '0 : EE7 consecuti&e primes, .,= distinct primes. !ldrich Ste&ens

-i.ionare $o&: or&onare $res$atoare sir


Info: ordonarea crescatoare pentru numere intregi; poate fi modificat pentru sortare de numere reale program ordonare_crescatoare_elemente; uses crt; type sir = array[1..100]of integer; var sir_neordonat, sir_ordonat : sir; var nr_elemente : integer; procedure ordonare(S1 : sir;var S var i , au" : integer; var sa_ordonat : #oolean; #egin sa_ordonat := false; : sir;n : integer!;

for i := 1 to n do S [i] := S1[i]; $%ile(sa_ordonat = false! do #egin sa_ordonat := true; for i := 1 to n & 1 do if S [i] ' S [i(1] t%en #egin sa_ordonat := false; au" := S [i]; S [i] := S [i(1]; S [i(1] := au"; end; end; end; procedure citire_sir(var S : sir; var n : integer!; var i : integer; #egin $riteln; $rite() *umarul de elemente al sirului : )!; readln(n!; $riteln; $riteln() +efiniti elementele)!; $riteln; for i := 1 to n do

#egin $rite() readln(S[i]!; end; end; procedure afisare_sir(S : sir; n : integer!; var i : integer; #egin for i := 1 to n do $rite() ),S[i]!; end; procedure info; #egin clrscr; $riteln; $riteln() end; #egin info; citire_sir(sir_neordonat,nr_elemente!; info; $riteln; $rite() -i definit urmatorul sir :)!; afisare_sir(sir_neordonat,nr_elemente!; ordonare(sir_neordonat,sir_ordonat,nr_elemente!; $riteln; $riteln; $rite() -cesta este sirul sortat :)!; afisare_sir(sir_ordonat,nr_elemente!; readln; end. element ),i,) : )!;

,rdonare crescatoare de numere intregi)!;

Option Explicit Dim A(20) As Integer Dim num, i, j, k, arr, temp As Integer

Private Su arr % 0

!omman"#$!lick()

Print &'our arra( contains) & *or k % 0 +o num , # Print &A&- &(&- arr- &))&- A(k) arr % arr . # /ext k En" Su

Private Su

*orm$0oa"()

num % Input1ox(&Intiali2e t3e si2e o4 (our arra()&) *or i % 0 +o num , # A(i) % Input1ox(&Enter (our arra() &) /ext i

5t3is 6ill sort (our arra( in ascen"ing or"er *or i % 0 +o num , # *or j % i . # +o num , # I4 A(i) 7 A(j) +3en temp % A(i) A(i) % A(j) A(j) % temp En" I4 /ext j /ext i

En" Su

You might also like