sigsegv error

please help me out in the following code which on execution gives sigsegv error

int main(void)

int n=0,k=0,i=0,j=0;

int p[100];











return 0;

Put your code in proper blocks please or give ideone link. It becomes easy to debug.

Can you provide the link of the problem…

There are a few things need to be changed in your code.

  1. You have not initialized the array p and not resetting it for every test cases.
  2. i value keeps on increasing, after a while i>100 giving you array index out of bound runtime error ( one possible reason for the sigsegv ).
  3. The closing brace ( " } " ) after i++ should not be there, move it to before return statement.

See your code which modified my me and got AC here.

The only problem is that you have not initialized the p array. I modified it, and now it works fine

[1], see in the problem statement you are given that  1 <= N <= 1000000000. But the array p in your code that holds the values has much smaller size.

You need not even use an array to hold the values, just calculate the values and display it.


You are storing answers of all the test cases in array p[] whose size is 100, so what about the test file which will have more than 100 test cases(its given there are about 100000 test cases). Answers of those are stored in a locations 100,101… and so on which are invalid, thus, you get RTE. Also, test your code for values like 1000000000. You answer doesnot come in the range of int(datatype of array p[]). Thus, again garbage value. You need not store the output , just display it this manner, see in my