DIM x AS INTEGER, y AS INTEGER DIM f AS INTEGER, p AS INTEGER CLS FOR x = 0 TO 40 y = x * x + x + 41 IF y MOD 2 = 0 THEN f = -1 ELSE f = 0 p = 3 DO WHILE f = 0 AND p * p <= y IF y MOD p = 0 THEN f = -1 ELSE f = 0 p = p + 2 LOOP IF f = 0 THEN PRINT "x="; x, "y="; y, "Is Prime" ELSE PRINT "x="; x, "y="; y, "Not Prime" END IF NEXT x END
Обнаружился странный эффект qBASIC. Последовательность команд: y:=x^2+x+41 для x=40 присваивает у значение 1681. Для p=41 значение p^2 также равно 1681, но значение выражения p^2<=y при этом оказывается ложным, хотя p^2 в этом случае должно быть равно у. В связи с этой странностью вместо х^2 использовано х*х, а вместо p^2 использовано р*р.
Результат выполнения программы: x= 0 y= 41 Is Prime x= 1 y= 43 Is Prime x= 2 y= 47 Is Prime x= 3 y= 53 Is Prime x= 4 y= 61 Is Prime x= 5 y= 71 Is Prime x= 6 y= 83 Is Prime x= 7 y= 97 Is Prime x= 8 y= 113 Is Prime x= 9 y= 131 Is Prime x= 10 y= 151 Is Prime x= 11 y= 173 Is Prime x= 12 y= 197 Is Prime x= 13 y= 223 Is Prime x= 14 y= 251 Is Prime x= 15 y= 281 Is Prime x= 16 y= 313 Is Prime x= 17 y= 347 Is Prime x= 18 y= 383 Is Prime x= 19 y= 421 Is Prime x= 20 y= 461 Is Prime x= 21 y= 503 Is Prime x= 22 y= 547 Is Prime x= 23 y= 593 Is Prime x= 24 y= 641 Is Prime x= 25 y= 691 Is Prime x= 26 y= 743 Is Prime x= 27 y= 797 Is Prime x= 28 y= 853 Is Prime x= 29 y= 911 Is Prime x= 30 y= 971 Is Prime x= 31 y= 1033 Is Prime x= 32 y= 1097 Is Prime x= 33 y= 1163 Is Prime x= 34 y= 1231 Is Prime x= 35 y= 1301 Is Prime x= 36 y= 1373 Is Prime x= 37 y= 1447 Is Prime x= 38 y= 1523 Is Prime x= 39 y= 1601 Is Prime x= 40 y= 1681 Not Prime
CLS
INPUT "k=", k
FOR m = 2 TO k
FOR n = 1 TO m - 1
a = m ^ 2 - n ^ 2: b = 2 * m * n: c = m ^ 2 + n ^ 2
PRINT m, n, a, b, c
NEXT n
NEXT m
END
Тестовое решение:
k=5
2 1 3 4 5
3 1 8 6 10
3 2 5 12 13
4 1 15 8 17
4 2 12 16 20
4 3 7 24 25
5 1 24 10 26
5 2 21 20 29
5 3 16 30 34
5 4 9 40 41
DIM f AS INTEGER, p AS INTEGER
CLS
FOR x = 0 TO 40
y = x * x + x + 41
IF y MOD 2 = 0 THEN f = -1 ELSE f = 0
p = 3
DO WHILE f = 0 AND p * p <= y
IF y MOD p = 0 THEN f = -1 ELSE f = 0
p = p + 2
LOOP
IF f = 0 THEN
PRINT "x="; x, "y="; y, "Is Prime"
ELSE
PRINT "x="; x, "y="; y, "Not Prime"
END IF
NEXT x
END
Обнаружился странный эффект qBASIC.
Последовательность команд:
y:=x^2+x+41 для x=40 присваивает у значение 1681.
Для p=41 значение p^2 также равно 1681, но значение выражения
p^2<=y при этом оказывается ложным, хотя p^2 в этом случае должно быть равно у.
В связи с этой странностью вместо х^2 использовано х*х, а вместо p^2 использовано р*р.
Результат выполнения программы:
x= 0 y= 41 Is Prime
x= 1 y= 43 Is Prime
x= 2 y= 47 Is Prime
x= 3 y= 53 Is Prime
x= 4 y= 61 Is Prime
x= 5 y= 71 Is Prime
x= 6 y= 83 Is Prime
x= 7 y= 97 Is Prime
x= 8 y= 113 Is Prime
x= 9 y= 131 Is Prime
x= 10 y= 151 Is Prime
x= 11 y= 173 Is Prime
x= 12 y= 197 Is Prime
x= 13 y= 223 Is Prime
x= 14 y= 251 Is Prime
x= 15 y= 281 Is Prime
x= 16 y= 313 Is Prime
x= 17 y= 347 Is Prime
x= 18 y= 383 Is Prime
x= 19 y= 421 Is Prime
x= 20 y= 461 Is Prime
x= 21 y= 503 Is Prime
x= 22 y= 547 Is Prime
x= 23 y= 593 Is Prime
x= 24 y= 641 Is Prime
x= 25 y= 691 Is Prime
x= 26 y= 743 Is Prime
x= 27 y= 797 Is Prime
x= 28 y= 853 Is Prime
x= 29 y= 911 Is Prime
x= 30 y= 971 Is Prime
x= 31 y= 1033 Is Prime
x= 32 y= 1097 Is Prime
x= 33 y= 1163 Is Prime
x= 34 y= 1231 Is Prime
x= 35 y= 1301 Is Prime
x= 36 y= 1373 Is Prime
x= 37 y= 1447 Is Prime
x= 38 y= 1523 Is Prime
x= 39 y= 1601 Is Prime
x= 40 y= 1681 Not Prime