Concept behind question

can you please explain to me the concept behind the question

@Kiraa_545, this is a very classical problem famously known as CHINESE REMAINDER PROBLEM . the Chinese remainder theorem states that if one knows the remainders of the Euclidean division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime.

you can solve this question by using brute force approach in which we start with 1 and one by one increment it and check if dividing it with given elements in num[] produces corresponding remainders in rem[]. Once we find such an x, we return it.
but this approach is quite inefficient in practice

fortunately for us , there is a formula stated in chinese remainder theorum ,
if you don’t know about it i highly suggest you to look at it first.

RESOURCES ------------------>>

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

start from time stamp : 1:19:31

for theory ref :-

if you want to look at bruteforce approach 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.