Problem description:

http://projecteuler.net/index.php?section=problems&id=48

The series, 11 + 22 + 33 + … + 1010 = 10405071317.

Find the last ten digits of the series, 11 + 22 + 33 + … + 10001000.


My solution:


The logic behind:

Simply put: Iterate over all numbers between 1 and 1000. For each iteration n, add nn.
Code uses bcmath functions, as the PHP pow function can’t handle numbers of this scale.

Solution (PHP):
<?php

for ($x = 1; $x < 1000; $x++)
{$sum = bcadd($sum, bcpow($x,$x));}
echo substr($sum,strlen($sum)-10,10);
?>
Answer
9110846700

Leave a Reply

You must be logged in to post a comment.