-
Notifications
You must be signed in to change notification settings - Fork 0
/
CRT_1.cpp
73 lines (63 loc) · 1.39 KB
/
CRT_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//============================================================================
// Name : CRT_1.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<iostream>
using namespace std;
int calc_inv(int a, int b)
{
int x, y;
int b0 = b, t, q;
int x0 = 0, x1 = 1;
if (b == 1)
return 1;
while (a > 1)
{
q = a / b;
t = b,
b = a % b,
a = t;
t = x0,
x0 = x1 - q * x0,
x1 = t;
}
if (x1 < 0) x1 += b0;
return x1;
}
int main()
{
int i,n, a[10], b[10], m[10], m_inv[10], prod = 1, sum = 0;
cout<< "\n Enter the numer of equations";
cin >>n;
for(i=0;i<n;i++)
{
cout<<"\nEnter the quation "<< i+1;
cout<<"\n Enter the value of a1 :";
cin>>a[i];
cout<<"\n Enter the value of b1 :";
cin>>b[i];
prod = prod * b[i];
}
for(i=0;i<n;i++)
{
m[i] = prod / b[i];
m_inv[i] = calc_inv(m[i],b[i]);
sum = sum + (a[i] * m[i] * m_inv[i]);
}
cout<<"The number is :" << (sum % prod);
}
==========OUTPUT===================
Enter the numer of equations3
Enter the quation 1
Enter the value of a1 :2
Enter the value of b1 :3
Enter the quation 2
Enter the value of a1 :3
Enter the value of b1 :5
Enter the quation 3
Enter the value of a1 :2
Enter the value of b1 :7
The number is :23