Curzon numbers: Difference between revisions

Content added Content deleted
No edit summary
(Curzon numbers in FreeBASIC)
Line 247: Line 247:
1513 1606 1614 1630 1665 1681 1690 1702 1785 1837
1513 1606 1614 1630 1665 1681 1690 1702 1785 1837
</pre>
</pre>

=={{header|FreeBASIC}}==
===Normal basic===
<lang freebasic>For k As Uinteger = 6 To 10 Step 2
Print "The first 50 Curzon numbers using a base of "; k; ":"
Dim As Ulongint count = 0, n = 1
Dim As Ulongint p = k
Do
If ((p + 1) Mod (k * n + 1)) = 0 Then
count += 1
If count <= 50 Then
Print Using "#####"; n;
If (count Mod 20) = 0 Then Print
Elseif count = 1000 Then
Print !"\nOne thousandth: "; n
Print : Print
Exit Do
End If
End If
n += 1
p *= k
Loop
Next k
Sleep</lang>


===GMP version===
{{libheader|GMP}}
<lang freebasic>#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</lang>


=={{header|Go}}==
=={{header|Go}}==