Seite 2 von 2

Verfasst: 04.06.2008 19:21
von Franky
So, my 2 cents:

Code: Alles auswählen

Global NewList Primzahlen.q()

AddElement(Primzahlen())
    Primzahlen()=2
    
wert.q=3
anf=GetTickCount_()
While CountList(Primzahlen())<1000000
      found=0
      wurzel.q=Sqr(wert)
      ForEach Primzahlen()
            If wert%Primzahlen()=0
                found=1
                Break
            EndIf
            If Primzahlen()>wurzel
                  Break
            EndIf
      Next 
      If found=0
            LastElement(Primzahlen())
            AddElement(Primzahlen())
                Primzahlen()=wert
      EndIf
      wert=wert+2
Wend  
ende=GetTickCount_()-anf
LastElement(Primzahlen())
MessageRequester("Die 1.000.000-te Primzahl lautet:",Str(Primzahlen())+Chr(13)+"Gefunden in "+Str(ende)+"ms")
Die 1.000.000-te Primzahl lautet:
15485863
Gefunden in 28141ms
OK
Die Linkedlist könnte natürlich noch geleert. Aber ich dachte mir, so kann man auch mal alle ausgeben lassen (viel spass beim durchlesen und einzeln nachrechnen <) )

Verfasst: 04.06.2008 20:08
von ZeHa

Code: Alles auswählen

For i.b=0 to 127
    If i=2 or i=3 or i=5 or i=7 or i=11 or i=13 or i=17 or i=19 or i=23 or i=29 or i=31 or i=37 or i=41 or i=43 or i=47 or i=53 or i=59 or i=61 or i=67 or i=71 or i=73 or i=79 or i=83 or i=89 or i=97 or i=101 or i=103 or i=107 or i=109 or i=113 or i=127
        Debug i
    EndIf
Next i
EDIT: Sogar mit Endlos-Loop-Faktor :mrgreen: