Given the area of three faces of the rectangular parallelepiped which has a common vertex. Our task is to find the sum of lengths of all 12 edges of this parallelepiped.
In geometry, a parallelepiped is a three-dimensional figure formed by six parallelograms. By analogy, it relates to a parallelogram just as a cube relates to a square or as a cuboid to a rectangle. A picture of a rectangular parallelepiped is shown below.Â
Examples:Â
Input: 1 1 1Â
Output: 12Input: 20 10 50
Output: 68
Approach: The area given are s1, s2 and s3 . Let a, b and c be the lengths of the sides that have one common vertex. Where ,Â
,Â
. It’s easy to find the length in terms of faces areas:Â
,Â
,Â
. The answer will be the summation of all the 4 sides, there are four sides that have lengths equal to a, b and c.
In the first example the given area s1 = 1, s2 = 1 and s3 = 1. So with the above approach, the value of a, b, c will come out to be 1. So the sum of the length of all 12 edges will be 4 * 3 = 12.
Below is the implementation of the above approach:Â Â
C++
// C++ program to illustrate // the above problem #include <bits/stdc++.h> using namespace std; Â
// function to find the sum of // all the edges of parallelepiped double findEdges( double s1, double s2, double s3) {     // to calculate the length of one edge     double a = sqrt (s1 * s2 / s3);     double b = sqrt (s3 * s1 / s2);     double c = sqrt (s3 * s2 / s1); Â
    // sum of all the edges of one side     double sum = a + b + c; Â
    // net sum will be equal to the     // summation of edges of all the sides     return 4 * sum; } Â
// Driver code int main() {     // initialize the area of three     // faces which has a common vertex     double s1, s2, s3;     s1 = 65, s2 = 156, s3 = 60; Â
    cout << findEdges(s1, s2, s3); Â
    return 0; } |
Java
// Java program to illustrate // the above problem Â
import java.io.*; Â
class GFG {    // function to find the sum of // all the edges of parallelepiped static double findEdges( double s1, double s2, double s3) {     // to calculate the length of one edge     double a = Math.sqrt(s1 * s2 / s3);     double b = Math.sqrt(s3 * s1 / s2);     double c = Math.sqrt(s3 * s2 / s1); Â
    // sum of all the edges of one side     double sum = a + b + c; Â
    // net sum will be equal to the     // summation of edges of all the sides     return 4 * sum; } Â
       // Driver code Â
    public static void main (String[] args) {             // initialize the area of three     // faces which has a common vertex     double s1, s2, s3;     s1 = 65 ; s2 = 156 ; s3 = 60 ; Â
    System.out.print(findEdges(s1, s2, s3));     } } Â
Â
// this code is contributed by anuj_67.. |
Python3
import math Â
# Python3 program to illustrate # the above problem Â
# function to find the sum of # all the edges of parallelepiped def findEdges(s1, s2, s3): Â
    # to calculate the length of one edge     a = math.sqrt(s1 * s2 / s3)     b = math.sqrt(s3 * s1 / s2)     c = math.sqrt(s3 * s2 / s1) Â
    # sum of all the edges of one side     sum = a + b + c Â
    # net sum will be equal to the     # summation of edges of all the sides     return 4 * sum Â
Â
# Driver code if __name__ = = '__main__' :      # initialize the area of three # faces which has a common vertex     s1 = 65     s2 = 156     s3 = 60 Â
    print ( int (findEdges(s1, s2, s3)))          # This code is contributed by # Shivi_Aggarwal |
C#
// C# program to illustrate // the above problem using System; Â
public class GFG{      // function to find the sum of // all the edges of parallelepiped static double findEdges( double s1, double s2, double s3) {     // to calculate the length of one edge     double a = Math.Sqrt(s1 * s2 / s3);     double b = Math.Sqrt(s3 * s1 / s2);     double c = Math.Sqrt(s3 * s2 / s1); Â
    // sum of all the edges of one side     double sum = a + b + c; Â
    // net sum will be equal to the     // summation of edges of all the sides     return 4 * sum; } Â
// Driver code Â
    static public void Main (){     // initialize the area of three     // faces which has a common vertex     double s1, s2, s3;     s1 = 65; s2 = 156; s3 = 60; Â
    Console.WriteLine(findEdges(s1, s2, s3));     } } Â
Â
// This code is contributed by anuj_67.. |
PHP
<?php // PHP program to illustrate // the above problem Â
// function to find the sum of // all the edges of parallelepiped function findEdges( $s1 , $s2 , $s3 ) {     // to calculate the length of one edge     $a = sqrt( $s1 * $s2 / $s3 );     $b = sqrt( $s3 * $s1 / $s2 );     $c = sqrt( $s3 * $s2 / $s1 ); Â
    // sum of all the edges of one side     $sum = $a + $b + $c ; Â
    // net sum will be equal to the     // summation of edges of all the sides     return 4 * $sum ; } Â
// Driver code Â
// initialize the area of three // faces which has a common vertex $s1 ; $s2 ; $s3 ; $s1 = 65; $s2 = 156; $s3 = 60; Â
echo findEdges( $s1 , $s2 , $s3 ); Â
// This code is contributed by Shashank ?> |
Javascript
// JavaScript program to illustrate // the above problem Â
// function to find the sum of // all the edges of parallelepiped function findEdges(s1, s2, s3) {     // to calculate the length of one edge     let a = Math.sqrt(s1 * s2 / s3);     let b = Math.sqrt(s3 * s1 / s2);     let c = Math.sqrt(s3 * s2 / s1); Â
    // sum of all the edges of one side     let sum = a + b + c; Â
    // net sum will be equal to the     // summation of edges of all the sides     return 4 * sum; } Â
// Driver code // initialize the area of three // faces which has a common vertex let s1 = 65, s2 = 156, s3 = 60; console.log(findEdges(s1, s2, s3)); //This code is contributed by chinmaya121221 |
120
Â
Time Complexity: O(logn) because the inbuilt sqrt function is being used
Auxiliary Space: O(1)
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!