RosettaCodeData/Task/Aliquot-sequence-classifica.../QBasic/aliquot-sequence-classifica...

57 lines
1.6 KiB
Plaintext

DECLARE FUNCTION PDtotal! (n!)
DECLARE SUB PrintAliquotClassifier (K!)
CLS
CONST limite = 10000000
DIM nums(22)
DATA 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 28, 496
DATA 220, 1184, 12496, 790, 909, 562, 1064, 1488
FOR n = 1 TO UBOUND(nums)
READ nums(n)
PRINT "Number"; nums(n); " :";
PrintAliquotClassifier (nums(n))
NEXT n
PRINT "Program normal end."
END
FUNCTION PDtotal (n)
total = 0
FOR y = 2 TO n
IF (n MOD y) = 0 THEN total = total + (n / y)
NEXT y
PDtotal = total
END FUNCTION
SUB PrintAliquotClassifier (K)
longit = 52: n = K: clase = 0: priorn = 0: inc = 0
DIM Aseq(longit)
FOR element = 2 TO longit
Aseq(element) = PDtotal(n)
PRINT Aseq(element); " ";
COLOR 3
SELECT CASE Aseq(element)
CASE 0
PRINT " Terminating": clase = 1: EXIT FOR
CASE K AND element = 2
PRINT " Perfect": clase = 2: EXIT FOR
CASE K AND element = 3
PRINT " Amicable": clase = 3: EXIT FOR
CASE K AND element > 3
PRINT " Sociable": clase = 4: EXIT FOR
CASE Aseq(element) <> K AND Aseq(element - 1) = Aseq(element)
PRINT " Aspiring": clase = 5: EXIT FOR
CASE Aseq(element) <> K AND Aseq(element - 2) = Aseq(element)
PRINT " Cyclic": clase = 6: EXIT FOR
END SELECT
COLOR 7
n = Aseq(element)
IF n > priorn THEN priorn = n: inc = inc + 1 ELSE inc = 0: priorn = 0
IF inc = 11 OR n > limite THEN EXIT FOR
NEXT element
IF clase = 0 THEN COLOR 12: PRINT " non-terminating"
COLOR 7
END SUB