# Very large numbers

Page 1 of 1

## 4 Replies - 1348 Views - Last Post: 19 December 2013 - 10:33 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=336867&amp;s=21c3a1eaf9a7af79cc3e8623704e9379&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 BillKindle

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 06-December 13

# Very large numbers

Posted 19 December 2013 - 09:45 AM

Im working (slowly) through the problems on Project Euler, I am currently on problem 16 and am having some difficulties. The number produced, 2^1000, is way to big to be stored accurately into any standard data types. I attempted to find each digit in the answer using the method below however this did not give me the correct answer, if you have any sugguestion they would be greatly appreciated. Thanks.

```For a As Integer = 1 To 1000
num = num * 2

If num >= 10 Then
position = position + 1 'When value reaches > 10 the position is moved on 1 place
Number(position) = 1 + Carry
Carry = 1
num = num - 10
For b As Integer = 1 To position
Number(B)/> = Number(B)/> * 2 + Carry
If Number(B)/> >= 10 Then
Carry = 1
Number(B)/> = Number(B)/> - 10
Else
Carry = 0
End If
Next
End If
Carry = 0
Next

For c As Integer = 1 To position
sum = sum + Number(c) 'Adds all integers found
Next

Console.WriteLine(sum) 'Displays sum
```

The value output is : 624 (which is incorrect)

Is This A Good Question/Topic? 0

## Replies To: Very large numbers

### #2 Ryano121

• D.I.C Lover

Reputation: 1461
• Posts: 3,289
• Joined: 30-January 11

## Re: Very large numbers

Posted 19 December 2013 - 09:48 AM

If you are solely using integer arithmetic then you can use the BigInteger class. Otherwise you may have to look into some 3rd party BigDecimal classes.

This post has been edited by Ryano121: 19 December 2013 - 09:48 AM

### #3 BillKindle

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 06-December 13

## Re: Very large numbers

Posted 19 December 2013 - 09:58 AM

Thanks for the response, I know BigInteger would work in this case but I find it sort of "cheating" as it's not really a data type found in Vb.net originally. I am trying to complete the problem using an alternative method and without the need to store the number in full.

### #4 TheCrazy8th

• New D.I.C Head

Reputation: 4
• Posts: 16
• Joined: 14-October 13

## Re: Very large numbers

Posted 19 December 2013 - 10:22 AM

I am just curious as to how you see this as "cheating" in any way...Code is all shortcuts really. To say that one shortcut is cheating and the rest aren't is kinda silly. If you wanna REALLY not cheat then you can't really use a language other than machine code lol. That's the way I look at it.

### #5 BillKindle

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 06-December 13

## Re: Very large numbers

Posted 19 December 2013 - 10:33 AM

Ok i see what you mean, but I'd just like to find a way of coming up with the answer using only the resources found in the base visual studio program that I have. I guess it's not really just cheating but I'm using the problems on Project Euler to try and learn as well as just simply answer them. I know I could use the Big Integer data type but I'd like to complete the problem without it.