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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Perfect totient numbers step by step in the Dart 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 Dart programming language

Source code in the dart programming language

import "dart:io";

var cache = List<int>.filled(10000, 0, growable: true);

void main() {
    cache[0] = 0;
    var count = 0;
    var i = 1;
    while (count < 20) {
        if (is_perfect_totient(i)) {
            stdout.write("$i ");
            count++;
        }
        i++;
    }
    print(" ");
}

bool is_perfect_totient(n) {
    var tot = 0;
    for (int i = 1; i < n; i++ ) {
       if (i.gcd(n) == 1) {
            tot++;
        }
    }
    int sum = tot + cache[tot];
    cache[n] = sum;
    return n == sum;
}


  

You may also check:How to resolve the algorithm Averages/Median step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the X86 Assembly programming language
You may also check:How to resolve the algorithm AKS test for primes step by step in the REXX programming language
You may also check:How to resolve the algorithm Zeckendorf number representation step by step in the Ada programming language
You may also check:How to resolve the algorithm Count in octal step by step in the COBOL programming language