Thursday 16 April 2009

PROJECT EULER #48

Link to Project Euler problem 48


The series, 11 + 22 + 33 + ... + 1010 = 10405071317.
Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.

Keep doing the math and only keep the last 10 digits after every multiplication.


using System;

namespace project_euler
{
class Program
{
static void Main()
{
//Problem 48
DateTime start = DateTime.Now;
long answer = 0;
for (int i = 1; i < 1001; i++)
{
long temp = i;
for (int j = 1; j < i; j++)
{
temp *= i;
temp %= 10000000000;
}
answer += temp;
answer %= 10000000000;
}
Console.WriteLine(answer % 10000000000);
TimeSpan time = DateTime.Now - start;
Console.WriteLine("This took {0}", time);
Console.ReadKey();
}
}
}

No comments: