SolveCongruence(a,c​,m)

Solve linear congruence ax == c(mod m)
121 Downloads
Updated 2 May 2016

View License

Solve linear congruence ax == c(mod m)
% ==== Couple examples ======
a = 51; c = 177; m = 1008;
S = SolveCongruence(a,c,m);
fprintf('\n')
a = 51; c = 689; m = 1008;
S = SolveCongruence(a,c,m);
fprintf('\n')
a = 893; c = 266; m = 2432;

S = SolveCongruence(a,c,m);
fprintf('\n')
a = 97; c = 1; m = 53460;
S = SolveCongruence(a,c,m);
fprintf('\n')

---- Output ------
4x + -79y = 3
1008x + 51y = 3
Solution: (4)1008 + (-79)51 = 3
Solutions
43
379
715

4x + -79y = 3
No solutions.

18x + -49y = 19
2432x + 893y = 19
Solution: (18)2432 + (-49)893 = 19
Solutions
1106
1234
1362
1490
1618
1746
1874
2002
2130
2258
2386
82
210
338
466
594
722
850
978

15x + -8267y = 1
53460x + 97y = 1
Solution: (15)53460 + (-8267)97 = 1
Solutions
45193

Cite As

John Harakas (2026). SolveCongruence(a,c,m) (https://www.mathworks.com/matlabcentral/fileexchange/56889-solvecongruence-a-c-m), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Version Published Release Notes
1.0.0.0