#include <iostream>
using namespace std;
class GCD {
private:
int X[20];
int Y[20];
int n;
int G[20];
public:
int calcGCD(int a, int b) {
if (b == 0) return a;
return calcGCD(b, a % b);
}
void read() {
cout << "Enter the number of elements (max 20): ";
cin >> n;
for (int i = 0; i < n; i++) {
cout << "Enter X[" << i+1 << "]: ";
cin >> X[i];
cout << "Enter Y[" << i+1 << "]: ";
cin >> Y[i];
if (X[i] <= 0 || Y[i] <= 0) {
cout << "Error: X and Y must be positive integers. Try again." << endl;
i--;
continue;
}
G[i] = calcGCD(X[i], Y[i]);
}
}
void display() {
cout << "X\tY\tGCD" << endl;
for (int i = 0; i < n; i++) {
cout << X[i] << "\t" << Y[i] << "\t" << G[i] << endl;
}
}
int MinGCD() {
int minGCD = G[0];
for (int i = 1; i < n; i++) {
if (G[i] < minGCD) minGCD = G[i];
}
return minGCD;
}
void compareMinGCD(GCD obj) {
int minGCD1 = MinGCD();
int minGCD2 = obj.MinGCD();
if (minGCD1 < minGCD2)
cout << "Object 1 has the minimum GCD." << endl;
else if (minGCD2 < minGCD1)
cout << "Object 2 has the minimum GCD." << endl;
else
cout << "Both objects have the same minimum GCD." << endl;
}
};
int main() {
GCD obj1, obj2;
cout << "Enter data for Object 1:" << endl;
obj1.read();
obj1.display();
cout << "Enter data for Object 2:" << endl;
obj2.read();
obj2.display();
obj1.compareMinGCD(obj2);
return 0;
}