How to resolve the algorithm Chowla numbers step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Chowla numbers step by step in the Wren 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 Wren programming language
Source code in the wren programming language
import "./fmt" for Fmt
import "./math" for Int, Nums
var chowla = Fn.new { |n| (n > 1) ? Nums.sum(Int.properDivisors(n)) - 1 : 0 }
for (i in 1..37) Fmt.print("chowla($2d) = $d", i, chowla.call(i))
System.print()
var count = 1
var limit = 1e7
var c = Int.primeSieve(limit, false)
var power = 100
var i = 3
while (i < limit) {
if (!c[i]) count = count + 1
if (i == power - 1) {
Fmt.print("Count of primes up to $,-10d = $,d", power, count)
power = power * 10
}
i = i + 2
}
System.print()
count = 0
limit = 35 * 1e6
i = 2
while (true) {
var p = (1 << (i -1)) * ((1<<i) - 1) // perfect numbers must be of this form
if (p > limit) break
if (chowla.call(p) == p-1) {
Fmt.print("$,d is a perfect number", p)
count = count + 1
}
i = i + 1
}
System.print("There are %(count) perfect numbers <= 35,000,000")
You may also check:How to resolve the algorithm Curzon numbers step by step in the Rust programming language
You may also check:How to resolve the algorithm Composite numbers k with no single digit factors whose factors are all substrings of k step by step in the Delphi programming language
You may also check:How to resolve the algorithm Sparkline in unicode step by step in the jq programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the Oz programming language
You may also check:How to resolve the algorithm Pentomino tiling step by step in the Julia programming language