Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. unsigned GCD(unsigned a, unsigned c) {
  2. if (a < c) {
  3. a ^= c;
  4. c ^= a;
  5. a ^= c;
  6. }
  7. unsigned tmp = 0;
  8. while (a%c!=0) {
  9. tmp = a%c;
  10. a = c;
  11. c = tmp;
  12. }
  13. return c;
  14.  
  15. }
  16.  
  17. int findValues(unsigned a, unsigned b, unsigned n) {
  18. if (a < b) {
  19. a ^= b;
  20. b ^= a;
  21. a ^= b;
  22. }
  23. unsigned div = GCD(a, b);
  24. if (n%div!= 0) { return 0; }
  25.  
  26.  
  27. if (a < b) {
  28. {
  29. for (int i = 1; i < n; i++) {
  30. unsigned x;
  31. unsigned y;
  32. if ((n - (i * a)) % b == 0) {
  33. x = i;
  34. y = (n - (i * a)) / b;
  35. cout << "C number of programs:" << x << "\nJava number of programs: " << y << endl;
  36. break;
  37. }
  38. }
  39. }
  40. }
  41. else if (b < a) {
  42. for (int i = 1; i < n; i++) {
  43. unsigned x;
  44. unsigned y;
  45. if ((n - (i * b)) % b == 0) {
  46. y = i;
  47. x = (n - (i * b)) / a;
  48. cout << "C number of programs:" << x << "\nJava number of programs: " << y << endl;
  49. break;
  50. }
  51. }
  52.  
  53. }
  54.  
  55. cout << "\nHe could debug a maximum of " << n / a << " C programs." << endl;
  56. }
  57.  
  58. int main() {
  59. unsigned a, b, n;
  60.  
  61. cout << "Minutes a=";
  62. cin >> a;
  63. cout << "Minutes b=";
  64. cin >> b;
  65. cout << "c=";
  66. cin >> n;
  67. findValues(a, b, n);
  68.  
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement