Advertisement
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 limit = Math.Min(a, b);
- bool hasValidNumber = false;
- for (int commonDivisor = 3; commonDivisor <= limit; commonDivisor++)
- {
- if (a % commonDivisor == 0 && b % commonDivisor == 0)
- {
- bool isPrime = true;
- for (int divider = 2; divider <= Math.Sqrt(commonDivisor); divider++)
- {
- if (commonDivisor % divider == 0)
- {
- isPrime = false;
- break;
- }
- }
- if (isPrime)
- {
- Console.Write(commonDivisor + " ");
- hasValidNumber = true;
- }
- }
- }
- if (!hasValidNumber)
- {
- Console.WriteLine(-1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement