APPLICATIONSDIVERS ★ PRIME NUMBERS : PRIME GENERATOR & PRIME FINDER|Amstrad Action) ★

Prime numbers : Prime generator & Prime finderApplications Divers
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

Primes play an important part in number theory and geometry; mathematicians since the Greeks have investigated their properties. They are also used in cryptography , for generating random numbers and for hashing in databases.

The one-line program generates the first 7500 prime numbers. It takes just under half an hour to run, so it seems a shame not to add a second line and save the data, which takes up 50k.

1 ' Prime generator
10 DIM p(7500): p(0)=1: p(1)=2: p(2)=3: FOR n=3 TO 7500: p(n)=p(n-1): ok=0: WHILE ok=0: ok=1: p(n)=p(n)+2: s=SQR(p(n)): m=0: WHILE ok*(p(m+1)<=s): m=m+1: d=p(n)/p(m): ok=d-INT(d): WEND:WEND: PRINT n,p(n):NEXT
20 OPENOUT"primdat": FOR n=1 TO 7500: WRITE #9,p(n): NEXT: CLOSEOUT

99 ' Prime finder
100 DIM p(7500): p(0)=1: OPENIN "primdat"
110 FOR n=1 TO 7500: INPUT #9,p(n): NEXT
120 WHILE -1
130 INPUT"Search from what number (0 to quit) ";x
140 IF x=0 THEN END
150 ok=0: x=x-1: IF x160 WHILE ok=0
170 ok=1: m=0: x=x+1: s=SQR(x)
180 WHILE ok*(p(m+1)<=s)
190 m=m+1: d=x/p(m): ok=d-INT(d)
200 WEND: WEND
210 PRINT"THE NEXT PRIME IS: ";x
220 WEND

It should be possible to extend the program to calculate primes up to 10^9. the accuracy limit of the Amstrad. The results would have to be saved to disk, for there is no space to extend the data array. The second program allows you to find a range of prime numbers from among the saved data.

AA

★ PUBLISHER: Amstrad Action
★ YEAR: 1987
★ CONFIG: AMSDOS + 64K
★ LANGUAGE:
★ LiCENCE: LISTING
★ AUTHOR: David Pollard (Thames St, Oxford)
 

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Applications » Compilation : Demon PD - PD 05 - Slideshow 1
» Applications » Contest CQWWDX
» Applications » Scrolling sur Amstrad (CPC Revue)
» Applications » RSX Info (Popular Computing Weekly)
» Applications » Um Gerador De Linhas De Data (Amstrad Magazine)
» Applications » Dischelp (Compute Mit)
Je participe au site:

» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.7-desktop/c
Page créée en 528 millisecondes et consultée 900 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.