The only problem is that you have not initialized the p array. I modified it, and now it works fine
, 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