Problem 57565. Easy Sequences 92: Number of Roots of a System of Linear Diophantine Equations
One of the tasks that Matlab is very good at, is in solving systems of linear equations.
In this problem we shall tackle a system of linear Diophantine Equations in which the roots are limited to certain range.
Given the number of variables n, positive integers, a, b and a root limit, L, create the function, numRoots(n,a,b,L), that outputs the number of posible integer root sets of the following system of equations:
with:
For example, if
, the system of equations:
and
, where
, has only one root set, namely:
. Therefore, numRoots(2,10,4,1) = 1.
If
, two of the possible roots of:
where: ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAL0AAAAoCAYAAACrfPvAAAAHoUlEQVR4Xu2cR6stRRDH3/sAZlcuRAwLQVEMCKILBfNKVIzIBQUjLlSeeWXCtBExofAQzAguRAygCwNmFBQFA6LgyogfQP8/6YK6fbonnek55zo9ULzrmenqqup/VVfV9Lh9W72qBWZmge0z07eqWy2wrYK+gmB2Fqign92SV4Ur6CsGZmeBCvrZLXlVuIK+YuD/YIHDpMQuol9EP7QpVEHfZqF6f10tsJcEu110nmgPJ+T3+ntD9G5O8Ar6dV3SrSPX6RL1my4RdkSVAPxrogNEj4j+Eh0hOtfNcXwO+BX0I67ETFkBvlNEd4menAj8zEkac5voN2d30py3Q+R/Xf+emlqTCvqZInVEtS8Tr7sD0GBbGvzHaY6rRaQ1qeth/XiF6A/RnhX0I650ZbXJAqQbl4hunAD8benUDslwj+gT0dEV9BWppS2QAj8592OiL0pPHvhbpL88zLswbZf0hu3k74TQ++u3fURfi3xeVVI3jHqwKNWasrZVtmovINi6ydO0Jrl1LGCWbSnwk2PfUBj8zPut6CPRhTlc5kBPnnamiAKFi/zoKJH1QO/U3zeHe+Rwt5SwXOCJIteKTg4y8DMGNKW4/7ST9Qz9/eqM5MHZWS/sQzeDy68J918K9+J1LGim/1hPCX7r6NCyvEqUDcQ50GMotiOKhWeDZWy7APAY+GMRBUN2GxnJoiizmwiHs60L1ocHGZEDRXcX4aT2+0jTL7BZN3mI7rTsWOTvArixxzHBbuS2pBi08yjsksVdKWMFviXBD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hOuhLvht7peSZ2jphPfN92Bjpb8LY1GwJ6HLXrbm1rscy//q08fAiKbwWG5wSscNQ5m1p50NuC/KkBqUHWAoR/E9M20Ns88GHxc6CHz4nBoPHHAow1PqmPCVJGJaLTPYnTsVXI41+ixN0k0xtg0lFJgd4+lQNwLHiqo2Z8UvcJMp+5ccuAfhkADxmL7nQJORtmFzuNpYOtDthWyA4Rqg30nifRPLWoQ+ZtGoNM+4lSzrMKeZjTonHuCx+i+U7R2Ec+4EszwBf6y4DeTrcus2ZTntQt8n846wp6clJSjdwXMMsY0Y+1SJ49ahoenkoeLxspJZErVYsQjambqJ/GvNjx7P2F8b1Af3B4kF2H9wh9QBinxUNkHauD1WnuVUV6gL4RRZtOAvd8yN4OZ0/cBX5TyROLn+vgkLfGhWdP1bOP+1op91Cf3J7C8sglhWtbnyXZbx6+CtBbl4hqv0s7bqjC9lbWijXPB1BZqjOVPLEe9sHDRbrh26y285U4l5Kz5TLpzdD1Wdm4EqC3ltLYL6f6GMkOHfEFjVX2Np7iuNS5oJyMpBSQ/3IIx+NqqzP66D302Qr6gZYDaBzmty/j2Z7ZtgBea0U9cM7UMPuChs5H7po0h5QQvs1G4YrTvSdqepE2oklaWVXQt5qoPlAtsIUtUCK92cLmqKLPwQIV9HNY5arjJgtU0FdAzM4CFfSzW/KqcAV9xcDsLFBBP7slrwr/C92UD0fNGf+rAAAAAElFTkSuQmCC)
are
and
. In fact, there are
possible root sets. Therefore, numRoots(4,20,6,3) = 16.
There are no possible roots for
and
, therefore in these cases the function should return: numRoots = 0.
-------------------------
NOTE: As an added challenge, only those solutions with Cody program size of less than or equal to 200 will be accepted.
Solution Stats
Problem Comments
-
1 Comment
Ramon Villamangca
on 7 Feb 2023
Update: Programs of cody size <= 200 is now accepted.
Solution Comments
Show commentsProblem Recent Solvers1
Suggested Problems
-
3886 Solvers
-
209 Solvers
-
7299 Solvers
-
147 Solvers
-
MATLAB Basics: Complex Conjugates
52 Solvers
More from this Author116
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!