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

?>

Generating Images using PHP


The four basic steps in creating an image in PHP are-

  1. Creating a canvas image on which to work.
  2. Drawing shape,text on that canvas.
  3. Output the final graphic obtained.
  4. Clean the resources.

 

the code for same will be like this—>

lets name it createimage.php

<?php
// set up image
$height = 200;
$width = 200;
$im = imagecreatetruecolor($width, $height); //this will create a canvas, height and width are passed as parameters
$white = imagecolorallocate ($im, 255, 255, 255); //this function will select colour for your image
$blue = imagecolorallocate ($im, 0, 0, 64);
// draw on image
imagefill($im, 0, 0, $blue); // paint a blue background on which to draw
imageline($im, 0, 0, $width, $height, $white); //draws a line from top left corner to bottom right corner
imagestring($im, 4, 50, 150, ‘Sales’, $white); // this function adds a label to the graph
// output image
Header (‘Content-type: image/png’);
imagepng ($im); //ends the output to the browser in PNG format

// clean up
imagedestroy($im);
?>