VBA. Große Zahlen.
alifa
Wie geht das mit größeren Zahlen, etwa bis n*10^25 (n von 1 bis 9). Bei diesem Makro wird Überlauf gemeldet, die gesuchte Zahl wird wohl größer sein! (N, imMakro: a)
Gruß, Erhard
'Ich suche eine natürliche Zahl N und ihren Nachfolger N+1. S(N) ist gleich der Quersumme
'(Summe aller Ziffern) von N, und S(N+1) ist die Quersumme der Zahl N+1.
'Welches ist die kleinste Zahl N, so dass sowohl S(N) als auch S(N+1) durch 7 teilbar sind
Sub ZweiAufeinanderFolgendeZahlenGesucht()
Dim a&, z%, t!
t = Timer
For a = 1000 To 2500000000
If Quersumme(a) Mod 7 = 0 And Quersumme(a + 1) Mod 7 = 0 Then
Cells(z + 1, 1) = a
z = z + 1
End If
Next
MsgBox " fertig in" & Round(Timer - t, 2) & " Sek"
End Sub
Public Function Quersumme(ByVal Zahl As Long) As Long
Dim nQuersumme As Long
Do While Zahl 0
nQuersumme = nQuersumme + (Zahl Mod 10)
Zahl = Zahl \ 10
Loop
Quersumme = nQuersumme
End Function