You are Here: Home >< Maths

# Linear Congruence Equation

Announcements Posted on
Last day to win £100 of Amazon vouchers - don't miss out! Take our quick survey to enter 24-10-2016
1. If I have an equation of the form An + B ≡ X mod 2X,
where A, B and X are all coprime to each other. X is a power of 2 if that makes any difference.

Is there a simple formula I can use to calculate the first solution? First solution meaning in the range [0, 2X]

I've been googling modular arithmetic, linear congruence, even tried Chinese Remainder Theorem for the last hour and keep going nowhere.

Am I missing something obvious or is there no neat solution?
2. (Original post by bencrossley1)
If I have an equation of the form An + B ≡ X mod 2X,
where A, B and X are all coprime to each other. X is a power of 2 if that makes any difference.

Is there a simple formula I can use to calculate the first solution? First solution meaning in the range [0, 2X]

I've been googling modular arithmetic, linear congruence, even tried Chinese Remainder Theorem for the last hour and keep going nowhere.

Am I missing something obvious or is there no neat solution?
It's quite simple. Let's do an example, 3n + 5 = 4 (mod 8).
Notice that any number that is congruent to 4 (mod 8) can be written as 8m + 4 for some m.
Hence 3n + 5 = 8m + 4 -> 8m - 3n = 1. We can solve this Diophantine equation either using the Euclidean algorithm or just trial and error, to get m = 2 and n = 5 as an initial solution. Thus the "first solution" for n is 5.

The procedure is, of course, the same regardless of the values of A, B, and X.
3. (Original post by HapaxOromenon3)
It's quite simple. Let's do an example, 3n + 5 = 4 (mod 8).
Notice that any number that is congruent to 4 (mod 8) can be written as 8m + 4 for some m.
Hence 3n + 5 = 8m + 4 -> 8m - 3n = 1. We can solve this Diophantine equation either using the Euclidean algorithm or just trial and error, to get m = 2 and n = 5 as an initial solution. Thus the "first solution" for n is 5.

The procedure is, of course, the same regardless of the values of A, B, and X.
I don't wish to use the Euclidean algorithm or trial and error. I am after a deterministic formula. Thanks for putting in the time though!

I'm doing some work which would be much faster given a formula, For example:
n=7 solves 2187n + 17459 ≡ 32768 mod 65536
therefore
n=7 solves 6561n + 85145 ≡ 131072 mod 262144

The numbers I intend to work with are only increasing. So T&E is a complete no go, and I dislike algorithms. Or at least, for what I am doing they will not be of use.
4. (Original post by bencrossley1)
I don't wish to use the Euclidean algorithm or trial and error. I am after a deterministic formula. Thanks for putting in the time though!

I'm doing some work which would be much faster given a formula, For example:
n=7 solves 2187n + 17459 ≡ 32768 mod 65536
therefore
n=7 solves 6561n + 85145 ≡ 131072 mod 262144

The numbers I intend to work with are only increasing. So T&E is a complete no go, and I dislike algorithms. Or at least, for what I am doing they will not be of use.
If you don't want to use the Euclidean Algorithm, which is the only thing that can help you, simply for ideological reasons, then you are simply an idiot. There is no explicit formula for solving the type of equation that you have described.
5. (Original post by HapaxOromenon3)
If you don't want to use the Euclidean Algorithm, which is the only thing that can help you, simply for ideological reasons, then you are simply an idiot. There is no explicit formula for solving the type of equation that you have described.
Calling me an idiot is unwarranted.

Given the general expression An + B ≡ C mod D

yes I would agree, no deterministic solution.

Given the added criteria that A = 3^a, B is not divisible by 2 or 3, C = 2^c and D = 2^c+1 it is possible that under these conditions that a formula may exist.

I already have a formula for a=0 and a=1. By inspection I expect to be able to generate further formulas and eventually a general one for any a.
6. (Original post by bencrossley1)
Calling me an idiot is unwarranted.

Given the general expression An + B ≡ C mod D

yes I would agree, no deterministic solution.

Given the added criteria that A = 3^a, B is not divisible by 2 or 3, C = 2^c and D = 2^c+1 it is possible that under these conditions that a formula may exist.

I already have a formula for a=0 and a=1. By inspection I expect to be able to generate further formulas and eventually a general one for any a.
Lol.

Posted from TSR Mobile

## Register

Thanks for posting! You just need to create an account in order to submit the post
1. this can't be left blank
2. this can't be left blank
3. this can't be left blank

6 characters or longer with both numbers and letters is safer

4. this can't be left empty
1. Oops, you need to agree to our Ts&Cs to register

Updated: July 10, 2016
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Today on TSR

### How does exam reform affect you?

From GCSE to A level, it's all changing

Poll
Useful resources

### Maths Forum posting guidelines

Not sure where to post? Read here first

### How to use LaTex

Writing equations the easy way

### Study habits of A* students

Top tips from students who have already aced their exams