need help with problem :NUKES(easy section) m getting SIGSEGV err on submition

#include <bits/stdc++.h>
using namespace std;

int main() {

long long int A,N,K,j,i;

      cin>>A>>N>>K;

long long int s[100];

  i=-1;

while(A!=0){
i++;
s[i]=A%(N+1);
A=A/(N+1);
}

while(i<K)
{
i++;
s[i]=0;
}

for(j=0;j<K;j++){
cout<<s[j]<<" ";
}

return 0;

}

Try this TC : 1 0 1
This is where your code is giving SIGSEGV error. This error occurs when your code tries to access the out-of-bound array index.

The problem is in this while loop

while (A != 0)               // below are the values for each iteration for above TC
    { 
        i++;                      //0->1->2->3->...->99->100
        s[i] = A % (N + 1);      //s[0]->s[1]->s[2]->...->s[100] and it throws error
        A = A / (N + 1);          // A always remain 1 for described TC -- (A= 1 / (0+1))
                             //so this loop goes on and on until it access the s[100] which is out-of-bound 
    }
2 Likes

Thanks Alot :slight_smile: i will correct it , Thanks for replying <3