Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned GCD(unsigned a, unsigned c) {
- if (a < c) {
- a ^= c;
- c ^= a;
- a ^= c;
- }
- unsigned tmp = 0;
- while (a%c!=0) {
- tmp = a%c;
- a = c;
- c = tmp;
- }
- return c;
- }
- int findValues(unsigned a, unsigned b, unsigned n) {
- if (a < b) {
- a ^= b;
- b ^= a;
- a ^= b;
- }
- unsigned div = GCD(a, b);
- if (n%div!= 0) { return 0; }
- if (a < b) {
- {
- for (int i = 1; i < n; i++) {
- unsigned x;
- unsigned y;
- if ((n - (i * a)) % b == 0) {
- x = i;
- y = (n - (i * a)) / b;
- cout << "C number of programs:" << x << "\nJava number of programs: " << y << endl;
- break;
- }
- }
- }
- }
- else if (b < a) {
- for (int i = 1; i < n; i++) {
- unsigned x;
- unsigned y;
- if ((n - (i * b)) % b == 0) {
- y = i;
- x = (n - (i * b)) / a;
- cout << "C number of programs:" << x << "\nJava number of programs: " << y << endl;
- break;
- }
- }
- }
- cout << "\nHe could debug a maximum of " << n / a << " C programs." << endl;
- }
- int main() {
- unsigned a, b, n;
- cout << "Minutes a=";
- cin >> a;
- cout << "Minutes b=";
- cin >> b;
- cout << "c=";
- cin >> n;
- findValues(a, b, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement