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;
}
arrow
arrow
    全站熱搜

    JerryCheng 發表在 痞客邦 留言(0) 人氣()