function findLargestPerimeter(base) {
let height;
if (base % 2 === 0) {
// If base is even, one possible solution is to set height = base/2 - 1
height = base / 2 - 1;
} else {
// If base is odd, one possible solution is to set height = base//2
height = Math.floor(base / 2);
}
// Calculate hypotenuse using Pythagorean theorem
const hypotenuse = Math.sqrt(height**2 + base**2);
// Check if all sides are integers
if (Number.isInteger(height) && Number.isInteger(hypotenuse)) {
return Math.floor(height + base + hypotenuse);
} else {
return -1;
}
}
function main() {
// Input the number of test cases
const T = parseInt(prompt("Enter the number of test cases:"));
for (let i = 0; i < T; i++) {
// Input base of the triangle for each test case
const B = parseInt(prompt("Enter the base of the triangle:"));
// Find and print the largest perimeter or -1 if no triangle is possible
const result = findLargestPerimeter(B);
console.log(result);
}
}
// Call the main function
main();