How to resolve the algorithm Perfect totient numbers step by step in the Draco programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Perfect totient numbers step by step in the Draco programming language

Table of Contents

Problem Statement

Generate and show here, the first twenty Perfect totient numbers.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Perfect totient numbers step by step in the Draco programming language

Source code in the draco programming language

proc nonrec gcd(word a, b) word:
    word c;
    while b ~= 0 do 
        c := a;
        a := b;
        b := c % b
    od;
    a
corp

proc nonrec totient(word n) word:
    word r, i;
    r := 0;
    for i from 1 upto n-1 do
        if gcd(n,i) = 1 then r := r+1 fi
    od;
    r
corp

proc nonrec perfect(word n) bool:
    word sum, x;
    sum := 0;
    x := n;
    while
        x := totient(x);
        sum := sum + x;
        x ~= 1
    do od;
    sum = n
corp

proc nonrec main() void:
    word seen, n;
    seen := 0;
    n := 3;
    while seen < 20 do
        if perfect(n) then
            write(n, " ");
            seen := seen + 1
        fi;
        n := n + 2
    od
corp

  

You may also check:How to resolve the algorithm Tic-tac-toe step by step in the Tcl programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the Ruby programming language
You may also check:How to resolve the algorithm Loops/Downward for step by step in the Lua programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the Factor programming language
You may also check:How to resolve the algorithm Menu step by step in the Batch File programming language