How to resolve the algorithm Chowla numbers step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Chowla numbers step by step in the FreeBASIC programming language
Table of Contents
Problem Statement
Chowla numbers are also known as:
The chowla number of n is (as defined by Chowla's function):
The sequence is named after Sarvadaman D. S. Chowla, (22 October 1907 ──► 10 December 1995), a London born Indian American mathematician specializing in number theory.
German mathematician Carl Friedrich Gauss (1777─1855) said:
Chowla numbers can also be expressed as:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Chowla numbers step by step in the FreeBASIC programming language
Source code in the freebasic programming language
' 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
You may also check:How to resolve the algorithm Bitmap/Histogram step by step in the Tcl programming language
You may also check:How to resolve the algorithm Execute HQ9+ step by step in the C++ programming language
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the Ring programming language
You may also check:How to resolve the algorithm Variables step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Compiler/lexical analyzer step by step in the Java programming language