Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- int nwd(int a, int b)
- {
- int c;
- do
- {
- if (a % b == 0) return b;
- c = a % b;
- if (b % c == 0) return c;
- a = b % c;
- if (c % a == 0) return a;
- } while (a % b != 0);
- }
- int main()
- {
- int t, a, b;
- std::cin >> t;
- for (int i = 1; i < t+1; i++)
- {
- std::cin >> a >> b;
- std::cout << nwd(a , b) <<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement