Valery Dauzhuk
Valery Dauzhuk

Reputation: 121

Modular Arithmetics and Big Powers

Is there a way i can calculate this in javascript. I need to solve such type of expressions for encrypting/decrypting.

const x = 1999 ** 5678 % 567;
console.log(x);

Upvotes: 1

Views: 29

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 370979

1999 ** 5678 is a big number which has about 19,000 digits. It's too large to fit in a number.

But you can use BigInts instead:

console.log((1999n ** 5678n % 567n).toString());

(I use toString above only so that it works in the Stack Snippet interface, which doesn't support BigInts yet.)

Upvotes: 2

Related Questions