def modular_inverse(arr, N, P):
    count = 0
    for x in arr:
        if (x * x) % P == 1 % P:
            count += 1
    return count