• + 0 comments

    Simple C++ solution using Back Tracking:

    int findPows(int X, int num, int N) {
        int count=0;
        int val = X-pow(num,N);
        if (val>0) {
            num+=1;
        }
        else {
            if (val==0) {
                count+=1;
            }
            return count;
        }
        return findPows(val,num,N)+findPows(X,num,N);
    }
    int powerSum(int X, int N) {
        
        int count = 0;
        count = findPows(X, 1, N);
        
        return count;
    }