RosettaCodeData/Task/Arithmetic-numbers/Yabasic/arithmetic-numbers.basic

41 lines
1.2 KiB
Plaintext

// Rosetta Code problem: http://rosettacode.org/wiki/Arithmetic_numbers
// by Jjuanhdez, 06/2022
N = 1 : ArithCnt = 0 : CompCnt = 0
print "The first 100 arithmetic numbers are:"
repeat
Div = 1 : DivCnt = 0 : Sum = 0
while True
Quot = int( N / Div)
if Quot < Div break
if mod(N, Div) = 0 then
if Quot = Div then //N is a square
Sum = Sum + Quot
DivCnt = DivCnt + 1
break
else
Sum = Sum + Div + Quot
DivCnt = DivCnt + 2
end if
end if
Div = Div + 1
end while
if mod(Sum, DivCnt) = 0 then //N is arithmetic
ArithCnt = ArithCnt + 1
if ArithCnt <= 100 then
print N using "####";
if mod(ArithCnt, 20) = 0 print
end if
if DivCnt > 2 CompCnt = CompCnt + 1
switch ArithCnt
case 100
print
case 1000 : case 10000 : case 100000 : case 1e6
print "The ", ArithCnt using "#######", "th arithmetic number is ", N using "####,###", " up to which ", CompCnt using "###,###", " are composite."
end switch
end if
N = N + 1
until ArithCnt >= 1000000