Algorithm
Problem Name: 2 AD-HOC - beecrowd | 1573
Problem Link:
Chocolate Factory
By Gabriel Duarte, UNIFESO Brazil
Timelimit: 1
One factory produces chocolate bars in cubes and parallelepipeds with the same volume. However, since the machine that produces chocolate cubes has been showing some problems, the owners asked you for help to fix this problems.
Your task is, given the size of the edges of the parallelepipeds chocolate, inform the size the edge of the cube form should have.
Input
The input contains several test cases. The first line of each test case contains three integers A, B and C (1 ≤ A, B, C ≤ 103), indicating the size of the edges of the parallelepiped. The input ends when A = B = C = 0, and should not be processed.
Output
For each input, you must print an integer that should be truncated, representing the size that the edge in cube form should have.
Sample Input | Sample Output |
170 867 253 |
334 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#include <math.h>
int main(void) {
int a, b, c;
while (scanf("%d %d %d", &a, &b, &c) == 3 && (a || b || c))
printf("%d\n", (int)cbrt(a*b*c));
return 0;
}
Copy The Code &
Try With Live Editor
Input
452 378 368
5 6 7
2 4 5
0 0 0
Output
397
5
3
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <cmath>
using namespace std;
int main(void) {
int a, b, c;
while (cin >> a >> b >> c and (a or b or c))
cout << int(cbrt(a*b*c)) << endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
452 378 368
5 6 7
2 4 5
0 0 0
Output
397
5
3
#3 Code Example with Java Programming
Code -
Java Programming
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String l;
String[] P;
int A, B, C;
while (!(l = read()).equals("0 0 0")) {
P = l.split("\\s+");
A = Integer.parseInt(P[0]);
B = Integer.parseInt(P[1]);
C = Integer.parseInt(P[2]);
out.println((int) Math.pow(A * B * C, 1.0 / 3.0));
}
out.close();
}
private static String read() throws IOException {
return in.readLine();
}
}
Copy The Code &
Try With Live Editor
Input
452 378 368
5 6 7
2 4 5
0 0 0
Output
397
5
3
#4 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("node:fs")
const input = readFileSync("/dev/stdin", "utf8")
.split("\n")
.map(line => line.split(" ", 3).map(value => Number.parseInt(value, 10)))
function main() {
const output = []
for (const line of input) {
if (line.every(edge => edge === 0)) break
output.push(
Math.trunc(
Math.cbrt(
line.reduce((prod, value) => prod * value, 1)
)
))
}
console.log(output.join("\n"))
}
main()
Copy The Code &
Try With Live Editor
Input
452 378 368
5 6 7
2 4 5
0 0 0
Output
397
5
3
#5 Code Example with Python Programming
Code -
Python Programming
while True:
a, b, c = [int(x) for x in str(input()).split()]
if a == 0 == b == 0 == c: break
v = (a*b*c) ** (1/3)
print(int(v))
Copy The Code &
Try With Live Editor
Input
452 378 368
5 6 7
2 4 5
0 0 0
Output
397
5
3