Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class GreatestCommonDivisor
- {
- static void Main(string[] args)
- {
- int a = int.Parse(Console.ReadLine());
- int b = int.Parse(Console.ReadLine());
- int commonDivisor = Math.Min(a, b);
- bool isPrime = false;
- while (commonDivisor >= 3)
- {
- if (a % commonDivisor == 0 && b % commonDivisor == 0)
- {
- for (int divider = 2; divider <= Math.Sqrt(commonDivisor); divider++)
- {
- if (commonDivisor % divider == 0)
- {
- Console.Write(commonDivisor + " ");
- isPrime = false;
- break;
- }
- }
- }
- commonDivisor--;
- }
- if (!isPrime)
- {
- Console.WriteLine(-1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment