I am getting runtime error for 3 testcases

here is my code https://ide.codingblocks.com/s/242840

@sshreya2912, your code is correct but actually you are getting TLE because you are using brute force solution which is quite inefficient in this case , you need to use CHINEESE REMAINDER THEORUM which enables you to find x in nlogn (where n is the size of rem and num)

you can learn more about it here in detail :-

If you have access to the vedio through your course then refer that else there is a youtube vedio (ref linkn below) you can refer that

start from time stamp : 1:19:31

for theory ref :-

In case of any doubt feel free to ask :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

I opted for Competetive Programming course in c++, I have a chinese remainder theorem wala video under Number Theory it is of 20 minutes, and this was the code taught in the video

Hello Shreya, no doubt your logic is alright but you are getting TLE because you are using brute force approach. The nos. are large enough so that they can overflow int also. So we need to use the formula that Bhaiya told in the video, that is
it is equal to the x = summation of (rem[i]*pp[i]*inv[i])
You are not using anything like this.
So pls implement this approach surely it will get Accepted with all the testcases.
And pls also make sure you use long long int as the nos. can overflow the int range.
I hope it is clear to you. In case it is clear to you pls mark it as resolve and provide the rating as well as feedback so that we can improve ourselves.
In case there is still some confusion pls let me know, I will surely try to help you out.
Thanks :slight_smile:
Happy Coding !!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.