smatskevich

GCD

Feb 27th, 2021
623
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. int GCD(int a, int b) {
  4.   if (a == 0 || b == 0) throw std::runtime_error("Zero params for GCD");
  5.  
  6.   // Алгоритм Евклида
  7.   while (true) {
  8.     int r = a % b;
  9.     if (r == 0) return b;
  10.     a = b;
  11.     b = r;
  12.   }
  13. }
  14.  
  15. int main() {
  16.   int a = 0, b = 0;
  17.   std::cin >> a >> b;
  18.  
  19.   std::cout << GCD(a, b);
  20.   return 0;
  21. }
  22.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×