Smallest Ten Digit Powers

This is a companion piece of  Largest Ten Digit Powers . The codes are almostly same,with a few changes only.

  1. Function befit(ByVal s As StringByVal num As LongAs Boolean 'tell if a string s contain all digit(0-9) for just num times 
  2. Dim b(9) As Long, t As Long 
  3. befit = True 'init 
  4. If Len(s) <> 10 * num Then befit = FalseExit Function 
  5. For i = 1 To Len(s) 
  6. t = Val(Mid(s, i, 1)) 
  7. b(t) = b(t) + 1 
  8. If b(t) > num Then befit = FalseExit Function 
  9. Next 
  10. End Function 
  11. Function mypower(ByVal num As Currency, ByVal power As LongAs String 'UDF to calculate powers of a 10-digit number 
  12. Dim b(), temp 
  13. ReDim b(1 To 2 * power) 
  14. ReDim s(1 To 2 * power) 
  15. 'The last two element of the result,i.e. num it self 
  16. b(2 * power - 1) = Val(Left(num, 5)) 'init 
  17. b(2 * power) = Val(Right(num, 5)) 'init 
  18. For i = 2 To power 
  19. temp = 0 
  20. For j = 2 * power To 1 Step -1 
  21. temp = b(j) * num + temp 
  22. b(j) = Format(Val(Right(temp, 5)), "00000"'100000 adic 
  23. temp = Int(temp / 10 ^ 5) 
  24. Next 
  25. Next 
  26. mypower = Join(b, ""'The final result 
  27. End Function 
  28. Private Sub Command1_Click() 
  29. Dim index As Long, j As Currency, s As String 
  30. Index = CLng(InputBox("Please enter an integer within 1-30", "Info", 2))
  31. For j =   3*Int(10 ^ (10 - 1 / index)/3)  To  9999999999# Step 3 'n times 0-9 must be divisible by 3 
  32. DoEvents 
  33. s = mypower(j, index) 'the result 
  34. If befit(s, index) Then 's contains 0-9 each for index times 
  35. Open "c:/"& index &".txt" For Binary As #1 'Output to a text file 
  36. Put #1, , j & "^" & index & "=" & s 'Print the result 
  37. Close #1 
  38. End If 
  39. End 
  40. Next
  41. End Sub 

Since it have to enum a mount of 10-digit numbers,I  compiled it to an windows applicationran and run  the program in 4 PCs with different index , I've got the first 18 numbers till now(Numbers of other index: are still running):

 

1023456789^1=1023456789
3164252736^2=10012495377283485696
4642110594^3=100033726751278963952981464584
5623720662^4=1000218682348975505736229176987914443536
6312942339^5=10026725211153654390647841773200637448888932595699
6813614229^6=100061094057342858338669213648989907272573726634945455718121
7197035958^7=1000174338562286975299093890542029857149684613078516674136378324154752
7513755246^8=10159126159182043894548182772732556416094700698382830384251729403677604659937536
7747685775^9=100588420220833267470480529930325768811210496267095564714166268334749167599758148193359375
7961085846^10=1022640693192423918177472081495528045704001257405737138779536432199258656683133613589649088809624576
8120306331^11=10122704098280838738172663899155037525077864931542099359740473382958509846605210754479164591281362667243664131
8275283289^12=103132237398088685094148078064865552159324856064887274905478374353291741047910665437929791704128950573536662022369961121
8393900487^13=1026903443699705827527536011508380184886293234662850067608075167429132223154193162185649469905953603798419838589572701415774734247
8626922994^14=12646865508335605494843998794325485046341519468022708717028070547609519671202542318242559727117330589393633676024803151817278793689169412096
8594070624^15=103034762496243931091455752211526072992924547837934076638161515185979607268158486084352819994377954771846242628607531128031703303609805578845368090624
8691229761^16=1059984945135973085116625441940958734567890938937942910046410302827750560860737374626331724228885721853160790705924439371252226476405367618058329962361885148161
8800389678^17=11390226244546010693396746234792908564082582116481391247700038553190598561445998201373250115023954747487287071642058604917672993155873874536685736231662530396074892197888
8807854905^18=101780066705166236878346559130256930813111042299349121630146805870467163387920998553309748134869974589535455566056948852225484079291126292377577073478873342409711802829742431640625

Fortunately,I got a bigger number ,it appears when index=26:

9160395852^26=10227518575824412357774543428738315554963808756628545271950823008826278208489241129245927140719397161241846684623365292876389607982052697908581050074069519609796563228194931373316940301945115333795271107340007386839663447290510415078963123506544174796388696064

 

Since  (10n)!*(10^10-10^(10-1/n))/((n!)^10 * 10^((10*n)-10^(10*n-1)) =0.31691419

That means it should exists 0.3169 numbers whose 26th power contains all digit for 26 times.But it exists!!! It's realy a wonder!!!

原文地址:https://www.cnblogs.com/fengju/p/6336225.html