主题:埃及分数
网虫一号
[专家分:1230] 发布于 2007-08-11 11:06:00
将1/A改写成1/A=1/X+1/Y(埃及分数)的所有形式,A,X,Y都是自然数,A的值由键盘输入.
回复列表 (共9个回复)
沙发
Matodied [专家分:7560] 发布于 2007-08-11 14:04:00
CLS
INPUT a
FOR i = a + 1 TO a * 2
FOR j = i TO a * i STEP i
IF j MOD a = 0 THEN k = j: EXIT FOR
NEXT j
s1 = k / a: s2 = k / i
s3 = s1 - s2
IF k MOD s3 = 0 THEN
PRINT "1 /"; a; "= 1 /"; i; "+ 1 /"; k / s3
END IF
NEXT i
END
板凳
snoopy7 [专家分:70] 发布于 2007-08-11 14:31:00
CLS
INPUT a
x = a
DO
x = x + 1
y = a
DO
y = y + 1
IF 1 / x + 1 / y = 1 / a AND x <> y THEN f = -1
LOOP UNTIL f OR 1 / x + 1 / y > 1 / a
LOOP UNTIL f
PRINT x, y
3 楼
小精灵1号 [专家分:1040] 发布于 2007-08-12 10:26:00
CLS
10 INPUT A, B
IF A > B OR B = 0 THEN 10
PRINT A; "/"; B; "=";
DO
C = B \ A + 1: A = A * C - B: B = B * C
PRINT "1/"; LTRIM$(STR$(C));
IF B MOD A = 0 THEN PRINT "+1/"; LTRIM$(STR$(B / A)): END
IF B MOD A <> 0 THEN PRINT "+";
LOOP
END
4 楼
我的电脑 [专家分:990] 发布于 2007-08-12 10:28:00
CLS
10 INPUT A, B
IF A > B OR B = 0 THEN 10
PRINT A; "/"; B; "=";
DO
C = B \ A + 1: A = A * C - B: B = B * C
PRINT "1/"; LTRIM$(STR$(C));
IF B MOD A = 0 THEN PRINT "+1/"; LTRIM$(STR$(B / A)): END
IF B MOD A <> 0 THEN PRINT "+";
LOOP
END
5 楼
yaoyusheng [专家分:460] 发布于 2007-08-12 13:17:00
强顶2楼!!!!
写得很不错.
.
6 楼
Matodied [专家分:7560] 发布于 2007-08-12 13:56:00
2楼是错的!!!!!!!!!!!!!
(比如输入6,它是死循环,什么结果也不出来。就算出来了结果也不符合题目的要求)
3、4楼的程序不符合要求。明明只要输入A,你的B是什么?
7 楼
QB小猪 [专家分:1200] 发布于 2007-08-13 11:02:00
楼上的,不就是楼主没给你加分吗???
气什么!!!
瞧我的!!!
CLS
10 INPUT A, B
IF A > B OR B = 0 THEN 10
PRINT A; "/"; B; "=";
DO
C = B \ A + 1: A = A * C - B: B = B * C
PRINT "1/"; LTRIM$(STR$(C));
IF B MOD A = 0 THEN PRINT "+1/"; LTRIM$(STR$(B / A)): END
IF B MOD A <> 0 THEN PRINT "+";
LOOP
END
8 楼
我的电脑 [专家分:990] 发布于 2007-08-13 11:09:00
CLS
INPUT a
x = a
DO
x = x + 1
y = a
DO
y = y + 1
IF 1 / x + 1 / y = 1 / a AND x <> y THEN f = -1
LOOP UNTIL f OR 1 / x + 1 / y > 1 / a
LOOP UNTIL f
PRINT x, y
9 楼
天尝地酒 [专家分:870] 发布于 2007-08-14 09:42:00
CLS
INPUT a, b
PRINT a; "/"; b; "=";
DO
c = b / a + 1: a = a * c - b: b = b * c
PRINT "1/"; LTRIM$(STR$(c))
IF b MOD a = 0 THEN PRINT "+";
IF a MOD b = 0 THEN PRINT c; "/"; b;
LOOP UNTIL c >= a
END
我来回复