------
## 最终结论
```python
def modular_inverse(arr, n, p):
    count = 0
    for num in arr:
        # Calculate modular inverse using Fermat's Little Theorem
        if pow(num, p-2, p) == num:
            count += 1
    return count

# Test cases
assert modular_inverse([1, 6, 4, 5], 4, 7) == 2
assert modular_inverse([1, 3, 8, 12, 12], 5, 13) == 3
assert modular_inverse([2, 3, 4, 5], 4, 6) == 1
```