RosettaCodeData/Task/Curzon-numbers/FreeBASIC/curzon-numbers-2.basic
2023-07-01 13:44:08 -04:00

30 lines
797 B
Text

#include once "gmp.bi"
Dim As Longint t = Len(__mpz_struct)
Dim As mpz_ptr pow = Allocate(t)
Dim As mpz_ptr z = Allocate(t)
mpz_init(pow): mpz_init(z)
For k As Uinteger = 2 To 10 Step 2
Print "The first 50 Curzon numbers using a base of"; k; ":"
Dim As Integer count = 0, n = 1
mpz_set_si(pow,k)
Do
mpz_add_ui(z,pow,1)
Dim As Integer d = k*n + 1
If mpz_divisible_ui_p(z,d) Then
count += 1
If count <= 50 Then
Print Using "#####"; n
If (count Mod 25) = 0 Then Print
Elseif count=1000 Then
Print "One thousandth: "; n
Print : Print
Exit Do
End If
End If
n += 1
mpz_mul_si(pow,pow,k)
Loop
Next k
Sleep