Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27348

VS 2010 Calculating large numbers using mod function

$
0
0
I need to calculate a large number (2^1000) exactly. I'm not looking in to the BigInter datatype because I need to solve this problem using the mod function.
The first and last few digits match with the solution, but the numbers in between do not. I also seem to missing one character (my length is 301 instead of 302).

So here is my solution:

1071508607186 3673657696446578688584996819638419456681984148449525760315136776945008641208936331120476162593410284 9467187236376236910051328026011343723220172891472721092385177686764993414352076852758129705982361677 4642017465270272151065978322812928158047434623418368563326552525242368 386837205668069376

The real solution:

1071508607186 2673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175 5314682518714528569231404359845775746985748039345677748242309854210746050623711418779541821530464749 83581941267398767559165543946077062914571196477686542167660429831652624 386837205668069376

My code:

Public Sub Twee()
Dim getal(302) As ULong
Dim ZeerGroot As String
Dim i As ULong
i = 0

For i = 0 To 302
getal(i) = ((2 ^ 1000) / (10 ^ (18 * i))) Mod 10 ^ 18
Debug.Print(getal(i))
Next

i = 0
For i = 0 To 16

ZeerGroot = getal(i) & ZeerGroot


Next
Debug.Print(ZeerGroot)


End Sub

(Please don't pay too much attention to the choice of names, I'm Dutch so I used Dutch names.)

I can't seem to figure out why this won't work.

Thanks, Scott

Viewing all articles
Browse latest Browse all 27348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>