A lizard is present on one corner of cube, It wants to reach diagonally opposite corner of cube. You have to calculate minimum distance lizard has to cover to reach its destination.
Note : Lizard can’t fly, it moves along the wall.
You are given a representing side of cube.you have to calculate minimum distance lizard has to travel.
Examples:
Input : 5
Output :11.1803
Input :2
Output :4.47214
As we have to calculate the minimum distance from one corner to another diagonally opposite corner. if lizard able to fly then the shortest distance will be length of diagonal. But it can’t.

So, to calculate minimum distance, just open the cube, as describe in diagram.
Let us suppose, lizard is initially at point E.and it has to reach at point A(as A is diagonally opposite to E).Now we have to find AE.
Just use Pythagoras theorem, As
AC=a
CE=CD+DE=2a

C++
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ll a = 5;
ll AC = a;
ll CE = 2 * a;
double shortestDistace = sqrt (AC * AC + CE * CE);
cout << shortestDistace << endl;
return 0;
}
|
Java
import java.util.*;
class solution
{
public static void main(String arr[])
{
int a = 5 ;
int AC = a;
int CE = 2 * a;
double shortestDistace = Math.sqrt(AC * AC + CE * CE);
System.out.println(shortestDistace);
}
}
|
Python3
import math
if __name__ = = '__main__' :
a = 5
AC = a
CE = 2 * a
shortestDistace = math.sqrt(AC * AC + CE * CE)
print (shortestDistace)
|
C#
using System;
class GFG
{
public static void Main()
{
int a = 5;
int AC = a;
int CE = 2 * a;
double shortestDistace = Math.Sqrt(AC * AC + CE * CE);
Console.Write(shortestDistace);
}
}
|
PHP
<?php
$a = 5;
$AC = $a ;
$CE = 2 * $a ;
$shortestDistance = (double)(sqrt( $AC * $AC +
$CE * $CE ));
echo $shortestDistance . "\n" ;
?>
|
Javascript
<script>
var a = 5;
var AC = a;
var CE = 2 * a;
var shortestDistace = Math.sqrt(AC * AC + CE * CE);
document.write( shortestDistace.toFixed(4));
</script>
|