diff --git a/main.js b/main.js index 46f23be..d06d18f 100644 --- a/main.js +++ b/main.js @@ -70,21 +70,29 @@ function compute(queue, modulus) { const stack = []; for (const token of queue) { if (typeof token === "bigint") { - stack.push(token % modulus); + stack.push(token); } else if (token === "+") { - const [a, b] = binaryOpPop(stack); + let [a, b] = binaryOpPop(stack); + a %= modulus; + b %= modulus; const c = (a + b) % modulus; stack.push(c); } else if (token === "-") { - const [a, b] = binaryOpPop(stack); + let [a, b] = binaryOpPop(stack); + a %= modulus; + b %= modulus; const c = (a - b) % modulus; stack.push(c); } else if (token === "*") { - const [a, b] = binaryOpPop(stack); + let [a, b] = binaryOpPop(stack); + a %= modulus; + b %= modulus; const c = (a * b) % modulus; stack.push(c); } else if (token === "/") { - const [a, b] = binaryOpPop(stack); + let [a, b] = binaryOpPop(stack); + a %= modulus; + b %= modulus; const binv = modinv(b, modulus); const c = (a * binv) % modulus; stack.push(c);