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



Related task

   Totient function


Also see

   the OEIS entry for   perfect totient numbers.
   mrob   list of the first 54


100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
 
PRINT$NUMBER: PROCEDURE (N);
    DECLARE S (7) BYTE INITIAL ('..... $');
    DECLARE (N, P) ADDRESS, C BASED P BYTE;
    P = .S(5);
DIGIT:
    P = P - 1;
    C = N MOD 10 + '0';
    N = N / 10;
    IF N > 0 THEN GO TO DIGIT;
    CALL PRINT(P);
END PRINT$NUMBER;
 
GCD: PROCEDURE (A, B) ADDRESS;
    DECLARE (A, B, C) ADDRESS;
    DO WHILE B <> 0;
        C = A;
        A = B;
        B = C MOD B;
    END;
    RETURN A;
END GCD;
 
TOTIENT: PROCEDURE (N) ADDRESS;
    DECLARE (I, N, S) ADDRESS;
    S = 0;
    DO I=1 TO N-1;
        IF GCD(N,I) = 1 THEN S = S+1;
    END;
    RETURN S;
END TOTIENT;
 
PERFECT: PROCEDURE (N) BYTE;
    DECLARE (N, X, SUM) ADDRESS;
    X = N;
    SUM = 0;
    DO WHILE X > 1;
        X = TOTIENT(X);
        SUM = SUM + X;
    END;
    RETURN SUM = N;
END PERFECT;
 
DECLARE N ADDRESS, SEEN BYTE;
SEEN = 0;
N = 3;
DO WHILE SEEN < 20;
    IF PERFECT(N) THEN DO;
        CALL PRINT$NUMBER(N);
        SEEN = SEEN+1;
    END;
    N = N+2;
END;
CALL EXIT;
EOF