Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
42
Task/Curzon-numbers/FreeBASIC/curzon-numbers-1.basic
Normal file
42
Task/Curzon-numbers/FreeBASIC/curzon-numbers-1.basic
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
' limit: k * n +1 must be smaller then 2^32-1
|
||||
|
||||
Function pow_mod(b As ULongInt, power As ULongInt, modulus As ULongInt) As ULongInt
|
||||
' returns b ^ power mod modulus
|
||||
Dim As ULongInt x = 1
|
||||
|
||||
While power > 0
|
||||
If (power And 1) = 1 Then
|
||||
x = (x * b) Mod modulus
|
||||
End If
|
||||
b = (b * b) Mod modulus
|
||||
power = power Shr 1
|
||||
Wend
|
||||
|
||||
Return x
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
For k As ULongInt= 2 To 10 Step 2
|
||||
Print "The first 50 Curzon numbers using a base of "; k; ":"
|
||||
Dim As ULongInt count, n = 1, p, m
|
||||
|
||||
Do
|
||||
m = k * n +1
|
||||
p = pow_mod(k, n ,m) +1
|
||||
If p = m Then
|
||||
count += 1
|
||||
If count <= 50 Then
|
||||
Print Using "#####"; n;
|
||||
If (count Mod 10) = 0 Then Print
|
||||
ElseIf count = 1000 Then
|
||||
Print : Print "One thousandth: "; n
|
||||
Print : Print
|
||||
Exit Do
|
||||
End If
|
||||
End If
|
||||
n += 1
|
||||
Loop
|
||||
|
||||
Next
|
||||
Sleep
|
||||
30
Task/Curzon-numbers/FreeBASIC/curzon-numbers-2.basic
Normal file
30
Task/Curzon-numbers/FreeBASIC/curzon-numbers-2.basic
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#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
|
||||
Loading…
Add table
Add a link
Reference in a new issue