My C++ simple solution


  • 0
    Q

    Very simple code processing digit by digit of the given array.

    int superPow(int a, vector<int>& b) {
            reverse(b.begin(), b.end());
            int MOD = 1337;
            unsigned long long pow10 = a%MOD ;
            unsigned long long ret = 1 ;
            
            for(int i =0 ; i <b.size(); i ++){
                //Use b[i] number of times element of pow10 sequence 
                for(int j =0 ; j<b[i]; j++){
                    ret = ((ret % MOD) *(pow10 % MOD)) % MOD;
                }
                // pow10 is the sequence a, a^10, a^100, a^1000, ...
                unsigned long long npow10 = pow10;
                for(int j =0; j<9 ; j ++)
                    npow10 = ((npow10 % MOD)*(pow10 % MOD)) % MOD;
                pow10=npow10;
            }
            
            return ret;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.