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
A square matrix as sum of symmetric and skew-symmetric matrices A square matrix as sum of symmetric and skew-symmetric matrices
Münchhausen Number Münchhausen Number
K-th digit in &#039;a&#039; raised to power &#039;b&#039; K-th digit in &#039;a&#039; raised to power &#039;b&#039;
Check whether given three numbers are adjacent primes Check whether given three numbers are adjacent primes
Sum of square of first n odd numbers Sum of square of first n odd numbers

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