You are viewing a single comment's thread. Return to all 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; }
Seems like cookies are disabled on this browser, please enable them to open this website
The Power Sum
You are viewing a single comment's thread. Return to all comments →
Simple C++ solution using Back Tracking: