3
$\begingroup$

I am trying to find ALL or a list of possible values for x satisfying: x MOD 9 ==2 AND (x+631) MOD 9 = 3 Using Mathematica. can anyone help? 2 is not the only answer 497 is another one since 497 mod 9 = 2 and 497 + 631 = 1128----- 1128 mod 9 = 3

$\endgroup$
2
  • 2
    $\begingroup$ Welcome to Mathematica StackExchange. It is advised that you show some prior attempts of solving your problem. To give you some starting point: FindInstance[Mod[x, 9] == 2 && Mod[x + 631, 9] == 3 && x < 100, x, PositiveIntegers, 100]? This gives all positive solutions to your equations, smaller than 100. $\endgroup$
    – Domen
    Aug 5 at 14:48
  • $\begingroup$ Ok thank you very much $\endgroup$ Aug 5 at 18:23

2 Answers 2

6
$\begingroup$

If you replace "Mod" by x== .. + 9 a1 you may use Reduce and solve for x. And as MMA assumes all variables to be complex, you must define the variables as integers E.g.

Reduce[{x == 2 + 9 a1 && 631 + x == 3 + 9 a2, {x, a1, a2} \[Element] 
   Integers}, x]

enter image description here

where c1 is an arbitrary integer.

$\endgroup$
3
$\begingroup$
Clear["Global`*"]

eqns = {9*m + 2 == x, 9*n + 3 == x + 631};

To just find examples, use FindInstance

FindInstance[eqns, {x, m, n}, NonNegativeIntegers, 10] // Sort

(* {{x -> 2, m -> 0, n -> 70}, {x -> 803, m -> 89, n -> 159}, 
    {x -> 4772, m -> 530, n -> 600}, {x -> 4790, m -> 532, n -> 602}, 
    {x -> 5744, m -> 638, n -> 708}, {x -> 5780, m -> 642, n -> 712}, 
    {x -> 5969, m -> 663, n -> 733}, {x -> 6923, m -> 769, n -> 839}, 
    {x -> 7346, m -> 816, n -> 886}, {x -> 8084, m -> 898, n -> 968}}

To find all solutions

sol = Solve[eqns, {x, m, n}, NonNegativeIntegers]

enter image description here

Verifying,

And @@ Assuming[C[1] ∈ Integers && C[1] >= 0, 
  eqns /. sol // Simplify]

(* True *)

The first ten solutions are

Table[sol /. C[1] -> c, {c, 0, 9}]

(* {{{x -> 2, m -> 0, n -> 70}}, {{x -> 11, m -> 1, n -> 71}}, 
    {{x -> 20, m -> 2, n -> 72}}, {{x -> 29, m -> 3, n -> 73}}, 
    {{x -> 38, m -> 4, n -> 74}}, {{x -> 47, m -> 5, n -> 75}}, 
    {{x -> 56, m -> 6, n -> 76}}, {{x -> 65, m -> 7, n -> 77}}, 
    {{x -> 74, m -> 8, n -> 78}}, {{x -> 83, m -> 9, n -> 79}}}

EDIT: Or directly solving the Mod expressions

Solve[{Mod[x, 9] == 2, Mod[x + 631, 9] == 3}, x, 
 NonNegativeIntegers][[1]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.