Not passing all the test case

question -https://codeforces.com/problemset/problem/1312/C

my solution -https://codeforces.com/contest/1312/submission/92993692

as my compiler giving correct ans the values of v[i]<k but codeforces giving me incorrect ans

please tell me why this is happening and how to correct this error

I think you are missing a check when ith power has value greater than 1 for some v[i], in that case also it’s impossible. Implement something like this

            while(a[i]>=k){
                v.pb(a[i]%k);
                a[i]/=k;
            }
            if(a[i]>0)v.pb(a[i]);
            int j;
            if(v.size()>=1) j = v.size()-1;
            else j = -1;
            
            for(;j>=0;j--){
                if(v[j]>1){  flag=1; break;}
                else if(v[j]==1){
                    if(st.find(j)!=st.end()){ flag=1; break;}
                    else st.insert(j);
                }
            }

https://codeforces.com/contest/1312/submission/93021609 sir i corrected my code but failing on 8th test case can you please check why this happening and will you add comments in your code i am unable to understand