#include <stdio.h>
// value 函式實作
int value(int type, int width, int height, int length) {
// 金屬對應的價值表
int metal_values[6] = {30, 10, 4, 5, 3, 9}; // 金、銀、銅、鉛、鐵、鈦
int metal_types[6] = {79, 47, 29, 82, 26, 22}; // 金屬類型代號
// 驗證金屬類型
int metal_index = -1;
for (int i = 0; i < 6; i++) {
if (type == metal_types[i]) {
metal_index = i;
break;
}
}
if (metal_index == -1) {
return -1; // 無效的金屬類型
}
// 驗證長、寬、高是否有效
if (width <= 0 || height <= 0 || length <= 0) {
return -2; // 無效的尺寸
}
// 計算最大的正方體邊長
int min_dimension = width;
if (height < min_dimension) min_dimension = height;
if (length < min_dimension) min_dimension = length;
// 從最大可能的邊長開始嘗試
int max_cube_size = 0;
for (int size = min_dimension; size > 0; size--) {
if (width % size == 0 && height % size == 0 && length % size == 0) {
max_cube_size = size;
break;
}
}
// 計算正方體的體積、單個正方體的價值,以及總價值
int cube_volume = max_cube_size * max_cube_size * max_cube_size;
int cube_value = cube_volume * cube_volume * metal_values[metal_index];
int total_cubes = (width / max_cube_size) * (height / max_cube_size) * (length / max_cube_size);
int total_value = cube_value * total_cubes;
return total_value;
}
int main() {
int type, width, height, length;
scanf("%d%d%d%d", &type
, &width
, &height
, &length
); printf("%d", value
(type
, width
, height
, length
)); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyB2YWx1ZSDlh73lvI/lr6bkvZwKaW50IHZhbHVlKGludCB0eXBlLCBpbnQgd2lkdGgsIGludCBoZWlnaHQsIGludCBsZW5ndGgpIHsKICAgIC8vIOmHkeWxrOWwjeaHieeahOWDueWAvOihqAogICAgaW50IG1ldGFsX3ZhbHVlc1s2XSA9IHszMCwgMTAsIDQsIDUsIDMsIDl9OyAvLyDph5HjgIHpioDjgIHpioXjgIHpiZvjgIHpkLXjgIHpiKYKICAgIGludCBtZXRhbF90eXBlc1s2XSA9IHs3OSwgNDcsIDI5LCA4MiwgMjYsIDIyfTsgLy8g6YeR5bGs6aGe5Z6L5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