In: Computer Science
Thank you all. my other code is working fine. It was my IDE issue.
This is the new code i am writing for the below question. please help as you always do:
a=int(input('Input a: '));
b=int(input('Input b: '));
c=int(input('Input c: '));
r=int(input('Input r: '));
s=int(input('Input s: '));
t=int(input('Input t: '));
x=2;
min_rst = min(r,s,t);
while(1):
if((x-a)%r==0):
if((x-b)%s==0):
if((x-c)%t==0):
break;
x=x+1;
print('The required number is: ',x);
Questions:
Write a Python program called crt.py
that finds the value of x that satisfies a system of congruencies
of the form:
x ≡ a (mod r)
x ≡ b (mod s)
x ≡ c (mod t)
where a, b, and c are integers; and r, s, and t are pairwise
relatively prime positive
integers (i.e., gcd(r, s) = gcd(s, t) = gcd(r, t) = 1). Your
program
prompts the user for the values of a, b, c, r, s, and t, and
outputs the value of
x that satisfies the system of congruencies. Hint: see the NumPy
Ntheory class
reference: http://docs.sympy.org/dev/modules/ntheory.html. Submit
your Python
source code crt.py.
Thank you
Solution:
a = int(input('Input a: ')) b = int(input('Input b: ')) c = int(input('Input c: ')) r = int(input('Input r: ')) s = int(input('Input s: ')) t = int(input('Input t: ')) x = 2 min_rst = min(r, s, t) while (1): if (x - a) % r == 0 and (x - b) % s == 0 and (x - c) % t == 0: break x = x + 1 print('The required number is: ', x)
Output: