回 帖 发 新 帖 刷新版面

主题:关于同构数的问题

[em10]怎样才能从1-100找出同构数。请各位大虾指点。

回复列表 (共14个回复)

沙发

CLS
FOR i = 1 TO 9
  IF i ^ 2 MOD 10 = i THEN PRINT i
NEXT i
FOR i = 10 TO 99
  IF i ^ 2 MOD 100 = i THEN PRINT i
NEXT i
FOR i = 100 TO 999
  IF i ^ 2 MOD 1000 = i THEN PRINT i
NEXT i
END


1
5
6
25
76
376
625

板凳

cls
for i=1 to 100
  if i mod 5=2 then i=i+3
  if  (i*i)mod(10^int(log(i)/log(10)))=i then print i
next

3 楼

s$ = "0"
DO
  l% = LEN(s$)
  x$ = SPACE$(l%)
  FOR i% = 1 TO l%
      a% = VAL(MID$(s$, l% - i% + 1, 1))
      c% = 0
      FOR j% = 1 TO l%
          k% = i% + j% - 1
          IF k% > l% THEN EXIT FOR
          b% = VAL(MID$(s$, l% - j% + 1, 1))
          c% = c% + a% * b% + VAL(MID$(x$, l% - k% + 1, 1))
          MID$(x$, l% - k% + 1, 1) = CHR$(48 + (c% MOD 10))
          c% = c% \ 10
      NEXT
      IF RIGHT$(s$, i%) <> RIGHT$(x$, i%) THEN EXIT FOR
  NEXT
  IF i% > l% THEN PRINT s$
  
  a% = VAL(RIGHT$(s$, 1))
  IF a% MOD 5 = 1 THEN a% = a% + 4 ELSE a% = a% + 1
  DO WHILE a% > 9
     a% = a% - 10
     MID$(s$, l%, 1) = CHR$(48 + a%)
     l% = l% - 1
     IF l% < 1 THEN
        a% = 1
        l% = 1
        s$ = "1" + s$
     ELSE
        a% = VAL(MID$(s$, l%, 1)) + 1
     END IF
  LOOP
     MID$(s$, l%, 1) = CHR$(48 + a%)
LOOP
-----------------------------------------------
0
1
5
6
25
76
376
625
9376
90625
109376
890625
------------------------
怎么都是376或者625的? 是不是还有什么规律?

4 楼

感谢各位大侠的指点。

5 楼

嘿嘿,再来一下.
------------------------------------------------------------
s$ = "5"            '或者 s$="6"
DO
  l% = LEN(s$)
  x$ = SPACE$(l%)
  FOR i% = 1 TO l%
      a% = VAL(MID$(s$, l% - i% + 1, 1))
      c% = 0
      FOR j% = 1 TO l%
          k% = i% + j% - 1
          IF k% > l% THEN EXIT FOR
          b% = VAL(MID$(s$, l% - j% + 1, 1))
          c% = c% + a% * b% + VAL(MID$(x$, l% - k% + 1, 1))
          MID$(x$, l% - k% + 1, 1) = CHR$(48 + (c% MOD 10))
          c% = c% \ 10
      NEXT
      IF RIGHT$(s$, i%) <> RIGHT$(x$, i%) THEN EXIT FOR
  NEXT
  IF i% > l% THEN
     PRINT s$
     ss$=s$
     jj%=0
  end if
  
  jj%=jj%+1
  s$=ltrim$(str$(jj%))+ss$
LOOP  '这里是不是需要加点什么条件啊?
--------------------------------------------------
得出结果:
5
25
625
90625
890625
2890625
12890625
212890625
8212890625
18212890625
918212890625
9918212890625
59918212890625
259918212890625
6259918212890625
56259918212890625
256259918212890625
2256259918212890625
92256259918212890625
392256259918212890625
7392256259918212890625
77392256259918212890625
977392256259918212890625
9977392256259918212890625
19977392256259918212890625
619977392256259918212890625
6619977392256259918212890625
106619977392256259918212890625
4106619977392256259918212890625
9004106619977392256259918212890625
109004106619977392256259918212890625
6109004106619977392256259918212890625
96109004106619977392256259918212890625
896109004106619977392256259918212890625
30896109004106619977392256259918212890625
230896109004106619977392256259918212890625
3230896109004106619977392256259918212890625
23230896109004106619977392256259918212890625
423230896109004106619977392256259918212890625
3423230896109004106619977392256259918212890625
23423230896109004106619977392256259918212890625
423423230896109004106619977392256259918212890625
7423423230896109004106619977392256259918212890625
57423423230896109004106619977392256259918212890625
557423423230896109004106619977392256259918212890625
1000557423423230896109004106619977392256259918212890625
11000557423423230896109004106619977392256259918212890625
811000557423423230896109004106619977392256259918212890625
6
76
376
9376
109376
7109376
87109376
787109376
1787109376
81787109376
40081787109376
740081787109376
3740081787109376
43740081787109376
743740081787109376
7743740081787109376
607743740081787109376
2607743740081787109376
22607743740081787109376
80022607743740081787109376
380022607743740081787109376
3380022607743740081787109376
93380022607743740081787109376
893380022607743740081787109376
5893380022607743740081787109376
95893380022607743740081787109376
995893380022607743740081787109376
90995893380022607743740081787109376
890995893380022607743740081787109376
3890995893380022607743740081787109376
103890995893380022607743740081787109376
9103890995893380022607743740081787109376
69103890995893380022607743740081787109376
769103890995893380022607743740081787109376
6769103890995893380022607743740081787109376
76769103890995893380022607743740081787109376
576769103890995893380022607743740081787109376
6576769103890995893380022607743740081787109376
76576769103890995893380022607743740081787109376
576576769103890995893380022607743740081787109376
2576576769103890995893380022607743740081787109376
42576576769103890995893380022607743740081787109376
442576576769103890995893380022607743740081787109376
9442576576769103890995893380022607743740081787109376
99442576576769103890995893380022607743740081787109376
999442576576769103890995893380022607743740081787109376
8999442576576769103890995893380022607743740081787109376
88999442576576769103890995893380022607743740081787109376

6 楼

1也是同够树
1^2=1
right$("1",len("1"))="1"

7 楼

[em2]谢谢,正要解这个题
再请教一个问题:输入任意5个数放在数组中,假定输入5个数为1,2,8,2,10,用三种方法打印出以下方阵
1 2 8 2 10
2 8 2 10 1
8 2 10 1 2
2 10 1 2 8
10 1 2 8 2
谢谢!

8 楼

a$="  1  2  8  2 10"
for i=1 to 5
    print a$
    a$=right$(a$,12)+left$(a$,3)
next

9 楼

.............

10 楼

[em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em10][em9]

我来回复

您尚未登录,请登录后再回复。点此登录或注册