Count array elements having modular inverse under given prime number P equal to itself | C ++ program to implement the above approach ; Function to get the count of elements that satisfy the given condition . ; Stores count of elements that satisfy the condition ; Traverse the given array . ; If square of current element is equal to 1 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int equvInverse ( int arr [ ] , int N , int P ) { int cntElem = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] * arr [ i ] ) % P == 1 ) { cntElem ++ ; } } return cntElem ; } int main ( ) { int arr [ ] = { 1 , 6 , 4 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int P = 7 ; cout << equvInverse ( arr , N , P ) ; }