RosettaCodeData/Task/Magic-constant/PureBasic/magic-constant.basic

26 lines
486 B
Plaintext

Procedure.i a(n.i)
n + 2
ProcedureReturn n*(Pow(n,2) + 1)/2
EndProcedure
Procedure.i inv_a(x.i)
k.i = 0
While k*(Pow(k,2)+1)/2+2 < x
k + 1
Wend
ProcedureReturn k
EndProcedure
OpenConsole()
PrintN("The first 20 magic constants are:")
For n.i = 1 To 20
Print(Str(a(n)) + " ")
Next n
PrintN("") : PrintN("")
PrintN("The 1,000th magic constant is " + Str(a(1000)))
For e.i = 1 To 20
PrintN("10^" + Str(e) + ": " + #TAB$ + Str(inv_a(Pow(10,e))))
Next e
CloseConsole()