主题:输出m到n之间的回文素数
zbwnrepyd
[专家分:0] 发布于 2009-04-14 19:21:00
回文知到吧
就比如
12221
13331
45554
······
最后更新于:2009-04-14 20:47:00
回复列表 (共4个回复)
沙发
1054122 [专家分:750] 发布于 2009-04-17 22:31:00
CLS
FOR i = 10000 TO 99999
bj = 1
FOR j = 2 TO i - 1
IF i MOD j = 0 THEN
bj = 0
EXIT FOR
END IF
NEXT j
g = i MOD 10
s = i \ 10 MOD 10
b = i \ 100 MOD 10
q = i \ 1000 MOD 10
w = i \ 10000
IF g * 10000 + s * 1000 + b * 100 + q * 10 + w <> i THEN
bj = 0
END IF
IF bj = 1 THEN
PRINT i;
END IF
NEXT i
END
板凳
1054122 [专家分:750] 发布于 2009-04-17 22:35:00
另外说明:12221不是素数
3 楼
gewenbo [专家分:450] 发布于 2009-04-25 11:51:00
试试我这个!
DIM m, n AS LONG
INPUT "M, N = ", m, n
IF m <= 2 OR n <= 2 THEN PRINT "Data Err!": END
FOR i = m TO n
flag = 1
FOR j = 2 TO i - 1
IF i MOD j = 0 THEN flag = 0: EXIT FOR
NEXT j
IF flag = 1 THEN
a$ = LTRIM$(RTRIM$(STR$(i))): b$ = ""
FOR ins = LEN(a$) TO 1 STEP -1
b$ = b$ + MID$(a$, ins, 1)
NEXT ins
IF a$ = b$ THEN PRINT i,
END IF
NEXT i
PRINT
END
4 楼
zbwnrepyd [专家分:0] 发布于 2009-04-27 12:34:00
多谢
我来回复