How to resolve the algorithm Erdős-Nicolas numbers step by step in the Nim programming language
How to resolve the algorithm Erdős-Nicolas numbers step by step in the Nim programming language
Table of Contents
Problem Statement
An Erdős–Nicolas number is a positive integer which is not perfect but is equal to the sum of its first k divisors (arranged in ascending order and including one) for some value of k greater than one. 24 is an Erdős–Nicolas number because the sum of its first 6 divisors (1, 2, 3, 4, 6 and 8) is equal to 24 and it is not perfect because 12 is also a divisor. 6 is not an Erdős–Nicolas number because it is perfect (1 + 2 + 3 = 6). 48 is not an Erdős–Nicolas number because its divisors are: 1, 2, 3, 4, 6, 8, 12, 16, 24 and 48. The first seven of these add up to 36, but the first eight add up to 52 which is more than 48. Find and show here the first 8 Erdős–Nicolas numbers and the number of divisors needed (i.e. the value of 'k') to satisfy the definition. Do the same for any further Erdős–Nicolas numbers which you have the patience for. As all known Erdős–Nicolas numbers are even you may assume this to be generally true in order to quicken up the search. However, it is not obvious (to me at least) why this should necessarily be the case.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Erdős-Nicolas numbers step by step in the Nim programming language
Source code in the nim programming language
import std/[sequtils, strformat]
proc main() =
const MaxNumber = 100_000_000i32
var dsum, dcount = repeat(1'i32, MaxNumber + 1)
for i in 2i32..MaxNumber:
for j in countup(i + i, MaxNumber, i):
if dsum[j] == j:
echo &"{j:>8} equals the sum of its first {dcount[j]} divisors"
inc dsum[j], i
inc dcount[j]
main()
You may also check:How to resolve the algorithm HTTPS/Authenticated step by step in the Nim programming language
You may also check:How to resolve the algorithm Create a file step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Perfect numbers step by step in the Go programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the RPL programming language
You may also check:How to resolve the algorithm Chinese remainder theorem step by step in the Perl programming language