I have this number x which i need to find in the (40 mod x) = 1
a possible answer for x is 3, or 39 as it goes into the number 40 and leaves a remainder of 1.
What kind of code would I need if I was to find all possible answers of x?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Mathematically, to solve
(a mod x) = b, just find all of the divisors ofa-bthat aren’t divisors ofa. e.g. for(40 mod x) = 1, find the divisors of 40 – 1 (i.e. 39), which are 3, 13, and 39. The divisors of 40 are 2, 4, 5, 8, 10, 20, 40. None of the numbers in the first set are in the second, so the solutions are 3, 13, and 19.For
(40 mod x) = 5, you find the divisors of 40 – 5 (i.e. 35), which are 5, 7, and 35. 5 is on the list of divisors of 40, but the other two aren’t, so the solutions are 7 and 35.Of course, for such small numbers, it’s more work to find all of the factors of
aanda-bthan it is to simply do all of the trial divisions ofabyx, so the right way to solve your problem is to take exactly the question you asked and put it into code (forgive my VB, I haven’t written any in the past 15 years or so…)