RosettaCodeData/Task/Long-primes/PureBasic/long-primes.basic

27 lines
783 B
Plaintext

#MAX=64000
If OpenConsole()=0 : End 1 : EndIf
Dim p.b(#MAX) : FillMemory(@p(),#MAX,#True,#PB_Byte)
For n=2 To Int(Sqr(#MAX))+1 : If p(n) : m=n*n : While m<=#MAX : p(m)=#False : m+n : Wend : EndIf : Next
Procedure.i periodic(v.i)
r=1 : Repeat : r=(r*10)%v : c+1 : If r<=1 : ProcedureReturn c : EndIf : ForEver
EndProcedure
n=500
PrintN(LSet("_",15,"_")+"Long primes upto "+Str(n)+LSet("_",15,"_"))
For i=3 To 500 Step 2
If p(i) And (i-1)=periodic(i)
Print(RSet(Str(i),5)) : c+1 : If c%10=0 : PrintN("") : EndIf
EndIf
Next
PrintN(~"\n")
PrintN("The number of long primes up to:")
PrintN(RSet(Str(n),8)+" is "+Str(c)) : n+n
For i=501 To #MAX+1 Step 2
If p(i) And (i-1)=periodic(i) : c+1 : EndIf
If i>n : PrintN(RSet(Str(n),8)+" is "+Str(c)) : n+n : EndIf
Next
Input()