Project Euler problem-48 last 10 digits in 1^1 + 2^2 + 3^3 + …….. + 1000^1000?

This is the solution to problem 48 of project euler:

    LANGUAGE USED: PHP


<?php

$str = ‘ ‘;

for($i = 1; $i <= 1000; $i++)
{
$str = bcadd($str, bcpow($i, $i)); // bcpow takes arguments as a string.
}
echo substr($str, -10);  //substr function prints the last 10 values in the substring

?>

Advertisements

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