Formula de Numere Prime

Embed Size (px)

Citation preview

  • 8/13/2019 Formula de Numere Prime

    1/25

    The Mathematical Tourist

    By Ivars Peterson

    August 8, 2008

    A New Formula for Generating Primes

    http:www!maa!orgmathtouristmathtourist"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 formulax2+x+ 1, for example,yields an unbroken string of ! primes, starting atx" !.

    #nother simple, prime$rich formula,x2+x+ 1%, generates prime numbers for all integer values of

    xfrom ! through 1&. Searching for a polynomial formula that produces all primes, however, wouldbe 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 paperpublished in theJournal of Integer Sequences, )owland defines his formula and proves that it

    generates only 1s and primes.

    (lending simplicity and mystery, -ric )owlands formula is a delightful composition in the music of

    the primes, one everyone can en*oy, 'effrey (hallitrecently $ommente&on his %e$ursivityblog. # professor at the /niversity of 0aterloo, Shallit is editor of theJournal of Integer Sequences.

    eres )owlands recursive formula for generating primes, as presented by Shallit in his blog.

    efine a314 " %.

    5or ngreater than or e6ual to 2, set a3n4 " a3n7 14 + gcd3n, a3n7 144. ere gcd means thegreatest common divisor.

    5or example, given that a314 " %, a324 " a314 + gcd32, %4 " % + 1 " 8.

    The prime generator is then a3n4 7 a3n7 14. The resulting numbers are the so$called first

    differences of the original se6uence.

    ere are the first 29 values of the ase6uence:

    %, 8, ;, 1!, 1&, 18, 1;, 2!, 21, 22, 99, 9

  • 8/13/2019 Formula de Numere Prime

    2/25

    )owland &es$ri)eshis formula in the A New *in& of ($ien$e blog. e notes that the formulaoriginated 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 wasnt expressly engineered for this purpose, )owland said. )owland went on toprove mathematically that this recurrence produces only 1s and primes. e has created a

    +athemati$a &emonstrationfor exploring the recurrence.

    )owlands formula is unlikely to lead to more efficient ways of generating large primes, a crucial

    operation in cryptography. is formula produces the primeponly after first generating 3p7 94=2 1s.So it takes a reallylong 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 formulas like )owlands> )ecently, 5rench mathematician (enoit ?loitre proved that

    by setting b314 " 1 and b3n4 " b3n7 14 + lcm3n, b3n7 144 for ngreater than or e6ual to 2,b3n4=b3n7 14 7 1 is either 1 or prime.

    'any other 6uestions remain. s there anything special about the choice of a314 " %> oes

    )owlands formula eventually generate all oddprimes> )owland suspects that it does, but theresmuch more to learn.

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

    new.html

    Sunday, July 20, 2008

    %utgers Gra&uate (tu&ent Fin&s

    New PrimeGenerating FormulaStudying 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 fewhours.

    %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.

    http://thenksblog.wordpress.com/2008/07/21/a-simple-recurrence-that-produces-complex-behavior-and-primes/http://thenksblog.wordpress.com/2008/07/21/a-simple-recurrence-that-produces-complex-behavior-and-primes/http://thenksblog.wordpress.com/http://www.wolframscience.com/summerschool/2009/http://demonstrations.wolfram.com/PrimeGeneratingRecurrence/http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.htmlhttp://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.htmlhttp://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.htmlhttp://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.htmlhttp://thenksblog.wordpress.com/2008/07/21/a-simple-recurrence-that-produces-complex-behavior-and-primes/http://thenksblog.wordpress.com/http://www.wolframscience.com/summerschool/2009/http://demonstrations.wolfram.com/PrimeGeneratingRecurrence/http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.htmlhttp://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.htmlhttp://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.htmlhttp://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html
  • 8/13/2019 Formula de Numere Prime

    3/25

    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 Institute33

    probably more than you)ll get from appearing onAmerican 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 &eracitythat 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 polynomialx5x5 -'

    comes close: it generates primes forx6 0, ', , ..., 78, but fails at

    x6 -0.

    ! slight &ariation, though, leads to a genuine prime3generating

    polynomial. %t is a conse*uence of the 9a&is3atiyase&ich3;utnam3

    ones, Sato, Wada, and Wiens actually wrote

    down such a polynomial. %t has = &ariables.

    http://www.claymath.org/millennium/Riemann_Hypothesis/http://www.claymath.org/millennium/http://en.wikipedia.org/wiki/Hilbert's_tenth_problemhttp://www.claymath.org/millennium/Riemann_Hypothesis/http://www.claymath.org/millennium/http://en.wikipedia.org/wiki/Hilbert's_tenth_problem
  • 8/13/2019 Formula de Numere Prime

    4/25

    !nother prime3generating formula comes from a '8- paper of W. #.

    ills. ills pro&ed that there exists a real numberAsuch that ?A7n@

    is a prime number for all integers nA '. #ere ?x@ is the greatest

    integer function, the greatest integer Bx. Cnfortunately, nobodyknows a good way to calculateAother than testing the numbers the

    formula is supposed to generate for primality, and then constructing

    Aby 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.

  • 8/13/2019 Formula de Numere Prime

    5/25

    a/n3'2, the so3called first differences of the original se*uence.

    4or example, here are the first 7 &alues of the ase*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

  • 8/13/2019 Formula de Numere Prime

    6/25

    b/n2 6 b/n3'2 5 lcm/n,b/n3'22 for nA ,

    then b/n2Hb/n3'23' is either ' or prime for all nA .

    Will

  • 8/13/2019 Formula de Numere Prime

    7/25

    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

  • 8/13/2019 Formula de Numere Prime

    8/25

    /nonymous said...

    9oes it make sense not to be an "experimentalmathematician" nowadays

    %f so, why

    1+) -M

    /nonymous said...

    there are properties of interest that depend on somethingbeing infinite in a way that can)t be approximated with

    finite ob+ects or is too complex to be computed withinreasonable time.

    if there is a way to test ones hypotheses it can makesense to )experiment).but often something works for )generic) ob+ects but notfor all.

    for example almost all s*uare matrices are in&ertible, soif you test this hypothesis by generating s*uare matriceswith uniformly random doubles in ?3','@ you will always/&ery high probability2 get an in&ertible matrix. so theexperiment would not help much. as we know the answeralready it)s ob&ious how to describe an experiment thatshows that some s*uare matrices are not in&ertible, but ifyour problem is at the frontier of mathematical

    knowledge it can be less ob&ious.

    for some *uestions about integer se*uencesexperimenting is &ery useful, for the poincarM con+ecturenot so much.

    )+2) -M

    4reakF(

  • 8/13/2019 Formula de Numere Prime

    9/25

    %)&e been playing around with the problem in F /forperformance2 and my program can calculate thedifferences of the first '0.000.000 numbers in these*uence in about =.= seconds on my amd=-/$#D2 3 best

    and worst run:

    gcc 3I7 3Wall 3o primes primes.c time .Hprimes JJHde&Hnull

    real 0m=.7'suser 0m=.=1ssys 0m0.0-1s

    real 0m=.=81suser 0m=.=1ssys 0m0.0E=s

    out of curiosity, % modified shawns haskell program /andassuming % didn)t break something in the meantime 3 this

    is the first time %)&e seen haskell2 this is it)s benchmarks 3again, best and worst:

    ghc 3I 3o shawn primes.hs time .Hshawn JJ Hde&Hnull

    real 0m=.'=8suser 0m=.08=ssys 0m0.001s

    real 0m=.78-suser 0m=.7Essys 0m0.07s

    the haskell3&ersion only generates the first 25numbers in the se*uence, as opposed to the F3&ersions

    10.000.000/might use less memory, though2

  • 8/13/2019 Formula de Numere Prime

    10/25

    #ere is the haskell % used:primes.hs

    and here is the F3&ersion:

    primes.c

    !nyone up for optimiDing a bit more /% suggest lookinginto a more efficient gcd, perhaps with caching2

    11+)3 /M

    4reakF(

  • 8/13/2019 Formula de Numere Prime

    11/25

    )+18 -M

  • 8/13/2019 Formula de Numere Prime

    12/25

    % actually also considered gmp to allow for really largenumbers, but taking into account the amount of time ittakes to calculate the se*uence +ust up to '00.000.000

    /well below any number that would re*uire gmp2 % figuredit would +ust slow down the whole process for anyreasonable application...

    What really needs impro&ement, is the gcd3algorithm 3%)&e been reading up on "accelerated integer gcd", andmore specifically "se*uential accelerated integer gcd"from the paper Impro"ements on the acceleratedinte&er 9C$ al&orithmas it seam either that, or theparallel &ersion from same paper is more or less the bestimplementation around.

    % guess if anyone)s got a cluster lying around, the parallel&ersion along with gmp might come in handy, but untilthat, % 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 wouldthe 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 Pint t 6 0Q

    while /& O6 02P

    http://www-lipn.univ-paris13.fr/~sedjelmaci/science3.pdfhttp://www-lipn.univ-paris13.fr/~sedjelmaci/science3.pdfhttp://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216777560000#c5774777177004978368http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216785360000#c6967451060644375323http://www-lipn.univ-paris13.fr/~sedjelmaci/science3.pdfhttp://www-lipn.univ-paris13.fr/~sedjelmaci/science3.pdfhttp://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216777560000#c5774777177004978368http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216785360000#c6967451060644375323
  • 8/13/2019 Formula de Numere Prime

    13/25

    t 6 &Q& 6 u R &Qu 6 tQ

    return tQ

    Seems to be slightly faster though not significantly.

    L gcc 3I7 3Wall 3o primes primes.c time .HprimesJJ Hde&Hnull

    real 0m'7.=suser 0m'7.E='ssys 0m0.070s

    L gcc 3I7 3Wall 3o primeseuclid primeseuclid.c time.Hprimeseuclid JJ Hde&Hnull

    real 0m'.-suser 0m'.'1=ssys 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 StephenWolfram was actually leading the summer school and wesee the con&ergence with the notion of "experimentalmathematics".

    So can anyone implement this using F!s2+10 /M

    http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216790820000#c8754226067187957151http://www.blogger.com/profile/04426474525236405685http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216793400000#c4732656306684781049http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216790820000#c8754226067187957151http://www.blogger.com/profile/04426474525236405685http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216793400000#c4732656306684781049
  • 8/13/2019 Formula de Numere Prime

    14/25

    4reakF(

  • 8/13/2019 Formula de Numere Prime

    15/25

    %)&e been doing some number3crunching, and along withthe realiDation that the accelerated algorithm doesn)treally offer a speed3up before there)s a E3bit difference in

    the siDe of n and a/n3'2, % think gmp will definitely beneeded well before the new algorithm sa&es us time 3 %)mnot actually too sure it will e&er happen 3 on a&erage thisseems to hold: a/n2 6 .EUn, any cle&er arguments as towhy this would or would not e&er cause a E /or more2 bitdifference in siDes

    6+7 -M

    ;seudonymsaid...

    Shawn:

    rowlandSe*uence 6 filter /H6 '2 L DipWith /32 /tail as2 aswhereas 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 ofinefficiency in your code.

    2+1 /M

    /nonymous said...

    % agree with ;seudonym, it can be calculated withoute&en doing any recursion in c. The gcd function isn)t a bigproblem, the euclidean is fast enough for me. Gut themain code would look like:

    int main/&oid2 Punsigned int a,b,p,nQ

    a 6 Qfor/n6QnO6'0000000Qn552 P

    http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216864440000#c6056015362355951028http://www.blogger.com/profile/04272326070593532463http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216881660000#c6903084703298234279http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216864440000#c6056015362355951028http://www.blogger.com/profile/04272326070593532463http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1216881660000#c6903084703298234279
  • 8/13/2019 Formula de Numere Prime

    16/25

    b 6 a 5 gcd/n,a2Qprintf/"Ri RiXn",n3',b3a2Qa 6 bQ

    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?'@6Q

    a?n@ :6 a?n3'@ 5 $F9?n, a?n3'@@

    %f you want to remember /memoiDe the &alues2 to speedit up:

    a?n@ :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,-=,=8

    %n?E@:6 9ifferences?R@Iut?E@6 P',',',E,7,',',',','',7,',',',',',',',',',',7

    %n?=@:6 9eleteFases?R,'@Iut?=@6 PE,7,'',7,7

    %n?@:6 ;rimeHZR

    http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1217013960000#c5903377398552943853http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1217013960000#c5903377398552943853
  • 8/13/2019 Formula de Numere Prime

    17/25

    Iut?@6 PTrue,True,True,True,True

    #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,78,EE8,'E'7',E7,7077,=0=-

    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,78,EE8,'E'7',7077,=0=-

    The formula can be seen as a "simple program" thatgenerates an output known to be in some sensecomplicated, a point made &ery generally in StephenWolfram)s 00 book "! New Vind of Science".

  • 8/13/2019 Formula de Numere Prime

    18/25

    large primes up too any stopping point for /n2without using any pre&ious primes in the processof generating these primes.

    #ere it is in ;ython code for all odd primesup too /n26 0000.% am not sure if it will indent properly inthis post because in pre&iew it shows no indents

    n6 3Qn'6 3-Qn6 3'Qn-6-QnE6'Qb'60Q+60a6?0@U000'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:

    i6n-while iJ6:a'6a'5iif a'[60000: a?a'@6a'i6i3'a'6a'5nif a'[60000: a?a'@6a'n-6n-5nEQn6n3n-

    for ii in range/'00002:i6Uii5'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 lastprime less than /n2 where n60000 and gi&es a total

    number of odd primes 6 ='.

  • 8/13/2019 Formula de Numere Prime

    19/25

    So odd primes do ha&e a pattern, complex as theirpatternmay be through summations and negations starting with

    /82.where this summation and negation ne&er produce an oddprime.

    %t is &ery slow but shows this complex pattern of the oddprimesafter the first summation of these = integers where noodd primesare produced at each point of the summation.

    585755'575

    Then continuing with the summations and negationsbelowwhere also no odd primes are produced when this pattern

    emerges.

    3

    5-5753=5E5-5753''5=5E5-5753'55=5E5-575

    3-5155=5E5-575

  • 8/13/2019 Formula de Numere Prime

    20/25

    37585155=5E5-5753-'5'05..

    etc.The pattern for the negations is +ust the differenceof 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 patternwhich increments by one from the pre&ious group.

    !ll the odd integers produced from thesesummations and negations are composite and all theodd 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 sci3mathon +uly -3E for 33"! prime $enerator that needs nopre&ious primes" will gi&e thecorrect indent for the ;ythonprogram % posted here.

    9an6+76 /M

    http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1217390820000#c6149640302512009124http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1217426340000#c2073576971476912903http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1217390820000#c6149640302512009124http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html?showComment=1217426340000#c2073576971476912903
  • 8/13/2019 Formula de Numere Prime

    21/25

    /nonymous said...

    This prime chain of 77 terms, '=' of which aredistinct, was found by means of a prime3producing

    generator closely akin to (ric

  • 8/13/2019 Formula de Numere Prime

    22/25

    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,

    788, 8'',-00

    any other &alues for the )a) &ariable abo&e, perhapsinfinitelymany, /but not all2may be substituted in the formula and produce longinitial primechains.for a 6 7 : 77 consecuti&e primes,a 6 : 7=a 6 - : 1'a 6 E : 1E1a 6 = : '='a 6 : ''E8a 6 1 : '

    a 6 8 : 1-a 6 '0 : '= etc.

    any other e*uations, perhaps infinitely many, /but notall2 may besubstitutedfor x\ 3 x 5 ' in the gi&en formula, or a morecomplicated

    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, = distinctprimes.

    !ldrich Ste&ens

  • 8/13/2019 Formula de Numere Prime

    23/25

    -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 : sir;n : integer!;var i , au" : integer;

    var sa_ordonat : #oolean;

    #egin

    sa_ordonat := false;

    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[i1] t%en

    #egin

    sa_ordonat := false;

    au" := S[i];

    S[i] := S[i1];

    S[i1] := 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

  • 8/13/2019 Formula de Numere Prime

    24/25

    #egin

    $rite() element ),i,) : )!;

    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() rdonare crescatoare de numere intregi)!;

    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.

    Option Explicit

    Dim A(20) As Integer

    Dim num, i, j, k, arr, temp As Integer

  • 8/13/2019 Formula de Numere Prime

    25/25

    Private Su !omman"#$!lick()

    arr % 0

    Print &'our arra contains &

    *or k % 0 +o num #

    Print &A&- &(&- arr- &)&- A(k)

    arr % arr . #

    /ext k

    En" Su

    Private Su *orm$oa"()

    num % Input1ox(&Intialie t3e sie 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