int hcf(int a , int h)
{
int temp;
while(1)
{
temp = a % h;
if(temp == 0)
{
return h;
}
a = h;
h = temp;
}
}
int relativePrimes(int* num , int n)
{
int count = 0;
for(int i = 0 ; i < n ; i++)
{
for(int j = i + 1 ; j < n ; j++)
{
int a = *(num + i);
int b = *(num + j);
int gcd = hcf(a , b);
if(gcd == 1)
{
count++;
}
}
}
return count;
}
全站熱搜