Skip to content
Programmingoneonone - Logo
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Computer System Architecture
    • Microprocessor
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
      • Data Structures Solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone - Logo
Programmingoneonone

Leetcode Super Pow problem solution

YASH PAL, 31 July 202422 January 2026

In this Leetcode Super Pow problem solution, Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.

Leetcode Super Pow problem solution

Leetcode Super Pow problem solution in Python.

class Solution:
    def superPow(self, a: int, b: List[int]) -> int:
        return pow(a,(int("".join([str(i) for i in b]))),1337)

Super Pow problem solution in Java.

public class Solution {
    public int superPow(int a, int[] b) {
        if(b==null || b.length==0) return 0;
        
        int len = b.length;

        int[] remainders = new int[len];
        int first = a % 1337;
        for(int i=len-1; i>=0; i--) {
            int[] nums = new int[11];
            nums[0] = 1;
            for(int j=1; j<11; j++) {
                nums[j] = (nums[j-1]*first) % 1337;
            }
            
            remainders[i] = nums[b[i]];
            first = nums[10];
        }
        int remainder = 1;
        for(int i=0; i<len; i++) {
            remainder = (remainder*remainders[i]) % 1337;
        }
        
        return remainder;
    }
}

Problem solution in C++.

int superPow(int a, vector<int>& b) {
        int result = 1;
        a %= 1337;
        for(int i = 0;i<b.size();i++){
            for(int j = 0;j<b[b.size()-i-1];j++){
                result=(result*a)%1337;
            }
            int a2 = (a*a)%1337;
            int a4 = (a2*a2)%1337;
            int a8 = (a4*a4)%1337; 
            a = (a8*a2)%1337;
        }
        return result;
    }

Problem solution in C.

int func(int a,int b){
    int ret=1;
    for(int i=0;i<b;i++){
        ret=ret*a%1337;
    }
    return ret;
}
int myPow(int a,int b,int zeroNum){
    int ret=func(a,b);
    for(int i=0;i<zeroNum;i++){
        ret=func(ret,10);
    }
    return ret;
}
int superPow(int a, int* b, int bSize){
    int ret=1;
    a%=1337;
    for(int i=0;i<bSize;i++){
        ret=ret*myPow(a,b[i],bSize-i-1)%1337;
    }
    return ret;
}

coding problems solutions Leetcode Problems Solutions Leetcode

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy
  • DMCA

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes