Advertisement
YavorJS

Greatest Common Divisor (CGD) - no Evklid

Jun 29th, 2016
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. class Program
  9. {
  10. static void Main()
  11. {
  12.  
  13. int a = int.Parse(Console.ReadLine());
  14. int b = int.Parse(Console.ReadLine());
  15. int oldDivisor = 1;
  16. int newDivisor = 1;
  17. int smaller = Math.Min(a, b);
  18. for (int i = oldDivisor; i <= smaller; i++)
  19. {
  20. if (a % i == 0 && b % i == 0)
  21. {
  22. newDivisor = i;
  23. }
  24. if (newDivisor > oldDivisor)
  25. {
  26. oldDivisor = newDivisor;
  27. }
  28. }
  29. Console.WriteLine(oldDivisor);
  30.  
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement