(In reply to
re: Similar solution by Charlie)
Sometimes we need only the rightmost n-1 digits. The modified algorithm:
5 for N=2 to 32
10 print N;" ";5^N;" ";:gosub 100:print Ans;" ";Ans//5^N
20 next
30 end
100 K=5^N:L=K:K$=cutspc(str(K))
101 while len(K$)<N:K$="0"+K$:wend
110 for I=1 to N
120 if mid(K$,len(K$)-I+1,1)="0" or mid(K$,len(K$)-I+1,1)="1" or mid(K$,len(K$)-I+1,1)="8" then
130 :K=K+L:K$=cutspc(str(K))
131 :while len(K$)<N:K$="0"+K$:wend
140 L=L*10
150 next
152 V=val(right(K$,N-1)):R=V@(5^N)
154 if R=0 then
155 :Ans=V
156 :else Ans=val(right(K$,N))
180 return
finds
2 25 25 1
3 125 625 5
4 625 625 1
5 3125 65625 21
6 15625 265625 17
7 78125 7265625 93
8 390625 97265625 249
9 1953125 697265625 357
10 9765625 6259765625 641
11 48828125 3759765625 77
12 244140625 275634765625 1129
13 1220703125 455322265625 373
14 6103515625 76666259765625 12561
15 30517578125 463775634765625 15197
16 152587890625 7557525634765625 49529
17 762939453125 39432525634765625 51685
18 3814697265625 699222564697265625 183297
19 19073486328125 6593265533447265625 345677
20 95367431640625 47336673736572265625 496361
21 476837158203125 254633426666259765625 534005
22 2384185791015625 4364664554595947265625 1830673
23 11920928955078125 6266367435455322265625 525661
24 59604644775390625 29479563236236572265625 494585
25 298023223876953125 6569396555423736572265625 22043237
26 1490116119384765625 49764443933963775634765625 33396353
27 7450580596923828125 323633767664432525634765625 43437389
28 37252902984619140625 6553496457636356353759765625 175919081
29 186264514923095703125 64966366626322269439697265625 348785525
30 931322574615478515625 447736994363367557525634765625 480753937
31 4656612873077392578125 9662663773633539676666259765625 2075041245
32 23283064365386962890625 93647676543332636356353759765625 4022137081
|
Posted by Charlie
on 2004-08-30 10:54:23 |