Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <string>;
- using ll = long long;
- int counter;
- namespace func{
- int gcd(int a, int b) {
- counter++;
- return b == 0 ? abs(a) : gcd(b, a % b);
- }
- bool validateNumber(std::string &number) {
- return find(begin(number), end(number), '.') == end(number);
- }
- }
- int main() {
- int n;
- std::cin >> n;
- std::string prev, next;
- std::cin >> prev;
- if (!func::validateNumber(prev)) {
- std::cout << "Sequence has float values!";
- return 0;
- }
- counter = 0;
- for (int i = 0; i < n - 1; i++) {
- std::cin >> next;
- if (!func::validateNumber(next)) {
- std::cout << "Sequence has float values!";
- return 0;
- }
- prev = std::to_string(func::gcd(std::stoi(next), std::stoi(prev)));
- }
- std::cout << prev << " " << counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement