Determining Ride Compatibility Using Modular Arithmetic on Letter Products
#include <bits/stdc++.h>
using namespace std;
int main() {
string comet, group;
cin >> comet >> group;
long product1 = 1, product2 = 1;
for (char ch : comet) {
product1 *= (ch - 'A' + 1);
}
for (char ch : group) {
product2 *= (ch - 'A' + 1);
}
if ((product1 % 47) == (product2 % 47)) {
cout << "GO" << endl;
} else {
cout << "STAY" << endl;
}
return 0;
}