Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
81
Task/Sphenic-numbers/PureBasic/sphenic-numbers.basic
Normal file
81
Task/Sphenic-numbers/PureBasic/sphenic-numbers.basic
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
Global Dim Factors(3)
|
||||
|
||||
Procedure.i Sphenic(N)
|
||||
Protected C, F, L, Q, res
|
||||
L = Sqr(N)
|
||||
C = 0
|
||||
F = 2
|
||||
While 1
|
||||
Q = N / F
|
||||
If N % F = 0
|
||||
Factors(C) = F
|
||||
C + 1
|
||||
If C > 3 : ProcedureReturn #False : EndIf
|
||||
N = Q
|
||||
If N % F = 0 : ProcedureReturn #False : EndIf
|
||||
If F > N : Break : EndIf
|
||||
Else
|
||||
F + 1
|
||||
If F > L
|
||||
Factors(C) = N
|
||||
C + 1
|
||||
Break
|
||||
EndIf
|
||||
EndIf
|
||||
Wend
|
||||
If C = 3
|
||||
res = #True
|
||||
Else
|
||||
res = #False
|
||||
EndIf
|
||||
ProcedureReturn res
|
||||
EndProcedure
|
||||
|
||||
OpenConsole()
|
||||
t0 = ElapsedMilliseconds()
|
||||
C = 0
|
||||
N = 2 * 3 * 5
|
||||
PrintN("Sphenic numbers less than 1,000:")
|
||||
While 1
|
||||
If Sphenic(N)
|
||||
C + 1
|
||||
If N < 1000
|
||||
Print(Str(N) + " ")
|
||||
If C % 15 = 0 : PrintN("") : EndIf
|
||||
EndIf
|
||||
If C = 200000
|
||||
Print("The 200,000th sphenic number is " + Str(N) + " = ")
|
||||
For I = 0 To 2
|
||||
Print(Str(Factors(I)))
|
||||
If I < 2 : Print(" * ") : EndIf
|
||||
Next I
|
||||
PrintN("")
|
||||
EndIf
|
||||
EndIf
|
||||
N + 1
|
||||
If N >= 1e6 : Break : EndIf
|
||||
Wend
|
||||
PrintN("There are " + Str(C) + " sphenic numbers less than 1,000,000")
|
||||
|
||||
C = 0
|
||||
N = 2 * 3 * 5
|
||||
PrintN(#CRLF$ + "Sphenic triplets less than 10,000:")
|
||||
While 1
|
||||
If Sphenic(N) And Sphenic(N+1) And Sphenic(N+2)
|
||||
C + 1
|
||||
If N < 10000
|
||||
Print("[" + Str(N) + ", " + Str(N+1) + ", " + Str(N+2) + "]")
|
||||
If C % 3 = 0 : PrintN("") : Else : Print(", ") : EndIf
|
||||
EndIf
|
||||
If C = 5000
|
||||
PrintN("The 5000th sphenic triplet is [" + Str(N) + ", " + Str(N+1) + ", " + Str(N+2) + "]")
|
||||
EndIf
|
||||
EndIf
|
||||
N + 1
|
||||
If N+2 >= 1e6 : Break : EndIf
|
||||
Wend
|
||||
PrintN("There are " + Str(C) + " sphenic triplets less than 1,000,000")
|
||||
|
||||
PrintN(StrF((ElapsedMilliseconds() - t0) / 1000, 2) + "sec.")
|
||||
PrintN(#CRLF$ + "Press ENTER to exit"): Input()
|
||||
CloseConsole()
|
||||
Loading…
Add table
Add a link
Reference in a new issue