REM Разложение числа на сумму квадратов
DECLARE SUB PROBA (A1 AS INTEGER, B1 AS INTEGER, C1 AS INTEGER, D1 AS INTEGER, N AS LONG)
INPUT "Введите натуральное число - ", N&
IF (N& MOD 2) = 0 THEN
REM Если число N - четное
PROBA 0, 0, 1, 1, N&
PROBA 0, 0, 0, 0, N&
PROBA 1, 1, 1, 1, N&
ELSE
REM Если число N - нечетное
PROBA 0, 0, 0, 1, N&
PROBA 0, 1, 1, 1, N&
END IF
END
SUB PROBA (A1 AS INTEGER, B1 AS INTEGER, C1 AS INTEGER, D1 AS INTEGER, N AS LONG)
'Подпрограмма перебора вариантов
Q = INT(SQR(N) + .5): ' Определение верхней границы
FOR A% = A1 TO Q STEP 2: S1 = A% * A%
FOR B% = B1 TO Q STEP 2: S2 = S1 + B% * B%
FOR C% = C1 TO Q STEP 2: S3 = S2 + C% * C%
FOR D% = D1 TO Q STEP 2
IF S3 + D% * D% = N THEN
PRINT "Искомые слагаемые :"
PRINT "a="; A%, "b="; B%, "c="; C%, "d="; D%
END
END IF
NEXT D%: NEXT C%: NEXT B%: NEXT A%
END SUB