Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
82
Task/Chowla-numbers/FreeBASIC/chowla-numbers.basic
Normal file
82
Task/Chowla-numbers/FreeBASIC/chowla-numbers.basic
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
' Chowla_numbers
|
||||
|
||||
#include "string.bi"
|
||||
|
||||
Dim Shared As Long limite
|
||||
limite = 10000000
|
||||
Dim Shared As Boolean c(limite)
|
||||
Dim As Long count, topenumprimo, a
|
||||
count = 1
|
||||
topenumprimo = 100
|
||||
Dim As Longint p, k, kk, limitenumperfect
|
||||
limitenumperfect = 35000000
|
||||
k = 2: kk = 3
|
||||
|
||||
Declare Function chowla(Byval n As Longint) As Longint
|
||||
Declare Sub sieve(Byval limite As Long, c() As Boolean)
|
||||
|
||||
Function chowla(Byval n As Longint) As Longint
|
||||
Dim As Long i, j, r
|
||||
i = 2
|
||||
Do While i * i <= n
|
||||
j = n \ i
|
||||
If n Mod i = 0 Then
|
||||
r += i
|
||||
If i <> j Then r += j
|
||||
End If
|
||||
i += 1
|
||||
Loop
|
||||
chowla = r
|
||||
End Function
|
||||
|
||||
Sub sieve(Byval limite As Long, c() As Boolean)
|
||||
Dim As Long i, j
|
||||
Redim As Boolean c(limite - 1)
|
||||
i = 3
|
||||
Do While i * 3 < limite
|
||||
If Not c(i) Then
|
||||
If chowla(i) = false Then
|
||||
j = 3 * i
|
||||
Do While j < limite
|
||||
c(j) = true
|
||||
j += 2 * i
|
||||
Loop
|
||||
End If
|
||||
End If
|
||||
i += 2
|
||||
Loop
|
||||
End Sub
|
||||
|
||||
Print "Chowla numbers"
|
||||
For a = 1 To 37
|
||||
Print "chowla(" & Trim(Str(a)) & ") = " & Trim(Str(chowla(a)))
|
||||
Next a
|
||||
|
||||
' Si chowla(n) = falso and n > 1 Entonces n es primo
|
||||
Print: Print "Contando los numeros primos hasta: "
|
||||
sieve(limite, c())
|
||||
For a = 3 To limite - 1 Step 2
|
||||
If Not c(a) Then count += 1
|
||||
If a = topenumprimo - 1 Then
|
||||
Print Using "########## hay"; topenumprimo;
|
||||
Print count
|
||||
topenumprimo *= 10
|
||||
End If
|
||||
Next a
|
||||
|
||||
' Si chowla(n) = n - 1 and n > 1 Entonces n es un número perfecto
|
||||
Print: Print "Buscando numeros perfectos... "
|
||||
count = 0
|
||||
Do
|
||||
p = k * kk : If p > limitenumperfect Then Exit Do
|
||||
If chowla(p) = p - 1 Then
|
||||
Print Using "##########,# es un numero perfecto"; p
|
||||
count += 1
|
||||
End If
|
||||
k = kk + 1 : kk += k
|
||||
Loop
|
||||
Print: Print "Hay " & count & " numeros perfectos <= " & Format(limitenumperfect, "###############################,#")
|
||||
|
||||
Print: Print "Pulsa una tecla para salir"
|
||||
Sleep
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue