/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Runtime Error /w/foo.js:25 const T = parseInt(prompt("Enter the number of test cases:")); ^ ReferenceError: prompt is not defined at main (/w/foo.js:25:15) at Object.<anonymous> (/w/foo.js:38:1) at Module._compile (node:internal/modules/cjs/loader:1356:14) at Module._extensions..js (node:internal/modules/cjs/loader:1414:10) at Module.load (node:internal/modules/cjs/loader:1197:32) at Module._load (node:internal/modules/cjs/loader:1013:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) at node:internal/main/run_main_module:28:49 Node.js v18.19.1 138ms 13.586 MiB
#2 Runtime Error /w/foo.js:25 const T = parseInt(prompt("Enter the number of test cases:")); ^ ReferenceError: prompt is not defined at main (/w/foo.js:25:15) at Object.<anonymous> (/w/foo.js:38:1) at Module._compile (node:internal/modules/cjs/loader:1356:14) at Module._extensions..js (node:internal/modules/cjs/loader:1414:10) at Module.load (node:internal/modules/cjs/loader:1197:32) at Module._load (node:internal/modules/cjs/loader:1013:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) at node:internal/main/run_main_module:28:49 Node.js v18.19.1 135ms 13.605 MiB

Code

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();

Information

Submit By
Type
Submission
Problem
P1027 Right triangle
Contest
Brain booster #2
Language
JavaScript (Node.js v18.19.1)
Submit At
2024-03-06 16:36:06
Judged At
2024-11-11 03:41:17
Judged By
Score
0
Total Time
138ms
Peak Memory
13.605 MiB