Smallest Ten Digit Powers
2009-01-11 22:41
225 查看
This is a companion piece of Largest Ten Digit Powers . The codes are almostly same,with a few changes only.
Function befit(ByVal s As String, ByVal num As Long) As Boolean 'tell if a string s contain all digit(0-9) for just num times
Dim b(9) As Long, t As Long
befit = True 'init
If Len(s) <> 10 * num Then befit = False: Exit Function
For i = 1 To Len(s)
t = Val(Mid(s, i, 1))
b(t) = b(t) + 1
If b(t) > num Then befit = False: Exit Function
Next
End Function
Function mypower(ByVal num As Currency, ByVal power As Long) As String 'UDF to calculate powers of a 10-digit number
Dim b(), temp
ReDim b(1 To 2 * power)
ReDim s(1 To 2 * power)
'The last two element of the result,i.e. num it self
b(2 * power - 1) = Val(Left(num, 5)) 'init
b(2 * power) = Val(Right(num, 5)) 'init
For i = 2 To power
temp = 0
For j = 2 * power To 1 Step -1
temp = b(j) * num + temp
b(j) = Format(Val(Right(temp, 5)), "00000") '100000 adic
temp = Int(temp / 10 ^ 5)
Next
Next
mypower = Join(b, "") 'The final result
End Function
Private Sub Command1_Click()
Dim index As Long, j As Currency, s As String
Index = CLng(InputBox("Please enter an integer within 1-30", "Info", 2))
For j = 3*Int(10 ^ (10 - 1 / index)/3) To 9999999999# Step 3 'n times 0-9 must be divisible by 3
DoEvents
s = mypower(j, index) 'the result
If befit(s, index) Then 's contains 0-9 each for index times
Open "c:/"& index &".txt" For Binary As #1 'Output to a text file
Put #1, , j & "^" & index & "=" & s 'Print the result
Close #1
End If
End
Next
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:
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!!!
Function befit(ByVal s As String, ByVal num As Long) As Boolean 'tell if a string s contain all digit(0-9) for just num times
Dim b(9) As Long, t As Long
befit = True 'init
If Len(s) <> 10 * num Then befit = False: Exit Function
For i = 1 To Len(s)
t = Val(Mid(s, i, 1))
b(t) = b(t) + 1
If b(t) > num Then befit = False: Exit Function
Next
End Function
Function mypower(ByVal num As Currency, ByVal power As Long) As String 'UDF to calculate powers of a 10-digit number
Dim b(), temp
ReDim b(1 To 2 * power)
ReDim s(1 To 2 * power)
'The last two element of the result,i.e. num it self
b(2 * power - 1) = Val(Left(num, 5)) 'init
b(2 * power) = Val(Right(num, 5)) 'init
For i = 2 To power
temp = 0
For j = 2 * power To 1 Step -1
temp = b(j) * num + temp
b(j) = Format(Val(Right(temp, 5)), "00000") '100000 adic
temp = Int(temp / 10 ^ 5)
Next
Next
mypower = Join(b, "") 'The final result
End Function
Private Sub Command1_Click()
Dim index As Long, j As Currency, s As String
Index = CLng(InputBox("Please enter an integer within 1-30", "Info", 2))
For j = 3*Int(10 ^ (10 - 1 / index)/3) To 9999999999# Step 3 'n times 0-9 must be divisible by 3
DoEvents
s = mypower(j, index) 'the result
If befit(s, index) Then 's contains 0-9 each for index times
Open "c:/"& index &".txt" For Binary As #1 'Output to a text file
Put #1, , j & "^" & index & "=" & s 'Print the result
Close #1
End If
End
Next
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 |
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!!!
相关文章推荐
- Smallest Ten Digit Powers
- Largest Ten Digit Powers
- Largest Ten Digit Powers
- Ten Digit Powers
- Ten Digit Powers
- Project Euler 题解 #30 Digit fifth powers
- projecteuler---->problem=30----Digit fifth powers
- Powers of Ten – Part I
- [华为机试练习题]29.Arrange an Array to Form a Smallest Digit
- Project Euler:Problem 30 Digit fifth powers
- Arrange an Array to Form a Smallest Digit
- 华为机试题:Arrange an Array to Form a Smallest Digit
- Digit fifth powers
- Problem 30 Digit fifth powers (暴力枚举)
- Euler: Digit fifth powers
- Arrange an Array to Form a Smallest Digit
- 欧拉工程第30题:Digit fifth powers
- Ten-digit Fractions
- Problem 30—Digit fifth powers
- Arrange an Array to Form a Smallest Digit