Advertisement
Radostin05

Untitled

Nov 18th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <numeric>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.     int x;
  9.     cin >> x;
  10.     int y;
  11.     cin >> y;
  12.     int z;
  13.     cin >> z;
  14.     int gcd=0;
  15.     int gcdNaXiY = 0;
  16.     int gcdNaXiZ = 0;
  17.     int gcdNaYiZ = 0;
  18.     int lcmNaXYZ=0;
  19.  
  20. if (x<10||x>100||y<10||y>100||z<10||z>100) {
  21.     cout<<"Invalid input data!"<<endl;
  22.     return 0;
  23. }
  24.  
  25.  
  26.  
  27.  
  28.     //gcd(x,y,z)
  29.     for (int i = 1; i <= x && i <= y && i <= z; ++i) {
  30.         if (x % i == 0 && y % i == 0 && z % i == 0) {
  31.             gcd = i;
  32.         }
  33.     }
  34.  
  35.     //gcd(x,y)
  36.     for (int j = 1; j <= x && j <= y; ++j) {
  37.         if (x % j == 0 && y % j == 0) {
  38.             gcdNaXiY = j;
  39.         }
  40.     }
  41.     //gcd(x,z)
  42.     for (int k = 1; k <= x && k <= z; ++k) {
  43.         if (x % k == 0 && z % k == 0) {
  44.             gcdNaXiZ = k;
  45.         }
  46.     }
  47.     //gcd(y,z)
  48.     for (int l = 1; l <= y && l <= z; ++l) {
  49.         if (y % l == 0 && z % l == 0) {
  50.             gcdNaYiZ = l;
  51.         }
  52.     }
  53.     lcmNaXYZ=(x*y*z*gcd)/(gcdNaXiY*gcdNaXiZ*gcdNaYiZ);
  54.  
  55.     cout << lcmNaXYZ;
  56.  
  57.     return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement