Horje
Sum of square of first n even numbers

Given a number n, find sum of square of first n even natural numbers. 

Examples:

Input : 3
Output : 56 
22 + 42 + 62 = 56

Input : 8
Output : 816
22 + 42 + 62 + 82 + 102 + 122 + 142 + 162 = 816

Recommended Practice

A simple solution is to traverse through n even numbers and find the sum of square.  

C++

<?php
// Simple PHP method to find sum of
// square of first n even numbers.
 
function squareSum($n)
{
    $sum = 0;
    for ($i = 1; $i <= $n; $i++)
        $sum += (2 * $i) * (2 * $i);
    return $sum;
}
 
 
    echo squareSum(8);
 
 
// This code is contributed by vt_m.
?>

Javascript

<?php
// Efficient PHP method to find sum of
// square of first n even numbers.
 
 
function squareSum( $n)
{
    return 2 * $n * ($n + 1) *
             (2 * $n + 1) / 3;
}
 
echo squareSum(8);
 
// This code is contributed by vt_m.
?>

Javascript

<script>
 
// JavaScript program to find sum of
// square of first n even numbers.
 
    function squareSum(n)
    {
        let sum = 0;
        for (let i = 1; i <= n; i++)
            sum += (2 * i) * (2 * i);
        return sum;
    }
 
// Driver code
 
            document.write(squareSum(8));
 
</script>

Output

816

Time complexity: O(1) since performing constant operations
Auxiliary Space: O(1) because constant extra space has been used




Reffered: https://www.geeksforgeeks.org


Mathematical

Related
Number of terms in Geometric Series with given conditions Number of terms in Geometric Series with given conditions
Palindromic Selfie Numbers Palindromic Selfie Numbers
Maximum rational number (or fraction) from an array Maximum rational number (or fraction) from an array
Average of odd numbers till a given odd number Average of odd numbers till a given odd number
Sum of fifth powers of the first n natural numbers Sum of fifth powers of the first n natural numbers

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12