Codeforces Round #138 (Div. 2) A. Parallelepiped

A. Parallelepiped
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.

Input

The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.

Output

Print a single number — the sum of all edges of the parallelepiped.

Sample test(s)
Input
1 1 1
Output
12
Input
4 6 6
Output
28
Note

In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.

 

     题目和算法分析:本题给出 一个长方体的 有“共同顶点”的3个面的面积 ,请你计算出 该长方体的12条棱的长度之和。

                           假设:3个面的面积分别是:x, y, z;  长宽高分别是:a, b, c;

                                   --->(1) a*b=x;   (2) a*c=y;  (3) b*c=z; 

                                   --->先让(1)与(2) 式 相除, --->  b/c = x/y ;  将此式与(3)式 联立 :---> c^2=(z*y)/x;

                                    同理可得: a^2=(x*y)/z;     b^2=(x*z)/y;

                                    然后用数学函数sqrt() 开方一下,计算出a, b, c, 再将它们加起来的和乘以4 输出就可以了!

     

#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>

using namespace std;


int main()
{
    int x, y, z;
    int a, b, c;

    while(scanf("%d %d %d", &x, &y, &z)!=EOF)
    {
        a=sqrt((y*x)/z);
        b=sqrt( (x*z)/y );
        c=sqrt( (z*y)/x);
        int n;
        n=(a+b+c)*4;
        printf("%d\n", n);
    }
    return 0;
}

 

          

posted @ 2014-10-26 19:11  我喜欢旅行  阅读(379)  评论(0编辑  收藏  举报