// Problem - https://[Log in to view URL]

class Solution {
    constructor() {
        this.mod = 1000000007n; // Converting it to BigInt
    }
    power(N, R) {
        return Number(this.getPowerValue(BigInt(N), BigInt(R)));    // Once we get the returned value as a BigInt number we convert it back to number.
    }
    getPowerValue(Num, Pow) {
        if (Pow === 0n) return 1n;                           // Since we are handling only BigInt numbers.
        else if (Pow % 2n === 0n) {                           // When the power is even 
            let temp = this.getPowerValue(Num, Pow / 2n);
            return (temp * temp) % this.mod;
        } else {                                            // When the power is odd 
            let temp = this.getPowerValue(Num, Pow - 1n);
            return (Num * temp) % this.mod;
        }
    }
}

sol = new Solution();
console.log(sol.power(3296675,5766923))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: