Advertisement
Pietras286

Gra Euklidesa

Dec 13th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. namespace Problem20
  2. {
  3.     class Program
  4.     {
  5.        public static void Main(string[] args)
  6.         {
  7.             int t = int.Parse(Console.ReadLine());
  8.             for (int i = 0; i < t; i++)
  9.             {
  10.                 string[] tab = Console.ReadLine().Split(' ');
  11.                 int a = int.Parse(tab[0]);
  12.                 int b = int.Parse(tab[1]);
  13.                 int tmp = 0;
  14.                 while (a != b)
  15.                 {
  16.                     tmp = a;
  17.                     a -= b;
  18.                     if (a < 0)
  19.                     {
  20.                         b = -a;
  21.                         a = tmp;
  22.                     }
  23.                 }
  24.                 Console.WriteLine(a + b);
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement