How to resolve the algorithm Chowla numbers step by step in the Nim programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Chowla numbers step by step in the Nim 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 Nim programming language
Source code in the nim programming language
import strformat
import strutils
func chowla(n: uint64): uint64 =
var sum = 0u64
var i = 2u64
var j: uint64
while i * i <= n:
if n mod i == 0:
j = n div i
sum += i
if i != j:
sum += j
inc i
sum
for n in 1u64..37:
echo &"chowla({n}) = {chowla(n)}"
var count = 0
var power = 100u64
for n in 2u64..10_000_000:
if chowla(n) == 0:
inc count
if n mod power == 0:
echo &"There are {insertSep($count, ','):>7} primes < {insertSep($power, ','):>10}"
power *= 10
count = 0
const limit = 350_000_000u64
var k = 2u64
var kk = 3u64
var p: uint64
while true:
p = k * kk
if p > limit:
break
if chowla(p) == p - 1:
echo &"{insertSep($p, ','):>10} is a perfect number"
inc count
k = kk + 1
kk += k
echo &"There are {count} perfect numbers < {insertSep($limit, ',')}"
You may also check:How to resolve the algorithm MD5 step by step in the Python programming language
You may also check:How to resolve the algorithm Count in octal step by step in the MiniScript programming language
You may also check:How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the Ada programming language
You may also check:How to resolve the algorithm Bitmap/Flood fill step by step in the Tcl programming language
You may also check:How to resolve the algorithm Strip block comments step by step in the J programming language