Help in App Related to Chinese Remainder Theorem

Hello I was building an app on the Chinese Remainder Theorem. The questions are generally like this:

When a number x is divided by 2, the remainder is 1. When it is divided by 3, the remainder is 2. When it is divided by 5, the remainder is 1. Find the least possible value of x.

I did the following code but every time I run it, it ends up showing only the variable ans as output.

The app takes the 3 divisors and the 3 remainders as the input.

Change that three level AND to an OR.

P.S. Initialize global ans at the start of the loop, so you can reuse the Button without having to reload the app.

P.P.S. To get the least (first) solution, break out of the loop after loading the Label.Text with the solution.



11% 3 = 2
11% 4 = 3
11%5 = 1

I tried these 3 but unfortunately now it is not showing anything as output. Here's the updated code.

Move the initialization higher. You were initializing a million times.

1 Like