Advertisement
OIQ

Untitled

OIQ
Sep 19th, 2021
752
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>;
  4.  
  5. using ll = long long;
  6. int counter;
  7.  
  8. namespace func{
  9.     int gcd(int a, int b) {
  10.         counter++;
  11.         return b == 0 ? abs(a) : gcd(b, a % b);
  12.     }
  13.  
  14.     bool validateNumber(std::string &number) {
  15.       return find(begin(number), end(number), '.') == end(number);
  16.     }
  17. }
  18.  
  19.  
  20. int main() {
  21.     int n;
  22.     std::cin >> n;
  23.     std::string prev, next;
  24.     std::cin >> prev;
  25.     if (!func::validateNumber(prev)) {
  26.         std::cout << "Sequence has float values!";
  27.         return 0;
  28.     }
  29.  
  30.     counter = 0;
  31.  
  32.     for (int i = 0; i < n - 1; i++) {
  33.         std::cin >> next;
  34.         if (!func::validateNumber(next)) {
  35.             std::cout << "Sequence has float values!";
  36.             return 0;
  37.         }
  38.         prev = std::to_string(func::gcd(std::stoi(next), std::stoi(prev)));
  39.     }
  40.  
  41.     std::cout << prev << " " << counter;
  42. }
Advertisement
RAW Paste Data Copied
Advertisement