Answer that given in soln will work only for below 2^63 . here is soln that work for more than 100+ char.O(n^2)time O(n)space


#1
string get(string A)
{    
    string res="";
    int carry=0;

// simply divide string by 2 what we used to do in simple divison
// i did same thing
// here carry tell the remainder…
for(int i=0;i<A.size();i++){
int k1=A[i]-‘0’,k2=-1;
if(!carry){
if(k1==0){
res+=‘0’;
carry=0;
}
if(k1==1){
res+=‘0’;
carry=1;
}
if(k1>1){
if(k1%2){
res+=char(k1/2 + ‘0’);
carry=1;
}
else{
res+=char(k1/2 + ‘0’);
carry=0;
}
}
}
else{
int p1=10;
p1+=k1;
res+=char(p1/2 +‘0’);
if(p1&1)carry=1;
else carry=0;
}

    }
    if(carry==1){
        return "-1";
    }
    string new1="";
    int ok=0;

// to avoid initial zeroes
for(int i=0;i<res.size();i++){
if(res[i]==‘0’ && ok==0)continue;
ok=1;
new1+=res[i];
}
return new1;
//return res;
}
int Solution::power(string A) {
string res="";
int n=A.size();
res=A;
if(res==“1”)return 0;
while(res.size()>1)
{
string ss=get(res);
if(ss.size()==0)return 0;
if(ss=="-1")return 0;
int k1=ss.back()-‘0’;
if(k1&1)return 0;
res=ss;

    }
    if(res=="2" || res=="4" || res=="8")return 1;
    if(res=="-1")return 0;
    return 1;
    
    
}

//1,267,650,600,228,229,401,496,703,205,376 use as test case work for 2^100.