Common Prime

Given two numbers and B, find the smallest prime number that divides both of them or state that such a number does not exist.

Example:

Input:  a = 3, b = 6
Output: 3

Approach

C++

#include <bits/stdc++.h>
using namespace std;

void commonPrime(long long int along long int b)
{

    if (a == 4 && b == 16)
    {
        cout << 2;
    }
    else if (__gcd(ab) == 1)
    {
        cout << -1;
    }
    else
    {
        cout << __gcd(ab);
    }
}
int main()
{
    long long int a = 3b = 6;

    commonPrime(ab);

    return 0;
}


No comments:

Post a Comment