Vasu Balakrishnan’s Blog

Project Euler #48

leave a comment »

The problem states Find the last ten digits of 11 + 22 + … + 10001000.

Answer: 9110846700

Solution: I started with C# built-in data types but soon I realized that I was exceeding the max value for the data types. Then I tried Microsoft.FSharp.Math.BigInt (FSharp.Core.dll) and was pretty straight forward.

var lOutput = Enumerable .Range(1, 1000) .Aggregate(BigInt.Zero, (pX, pY) => pX + BigInt.Pow(new BigInt(pY), new BigInt(pY))); var lAnswer = lOutput % BigInt.Pow(new BigInt(10), new BigInt(10));

Time: 465 ms

Advertisements

Written by nbvasu

May 14, 2009 at 10:58 pm

Posted in C#, Euler

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: