Count array elements having modular inverse under given prime number P equal to itself | Java 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
import java . io . * ; class GFG { static 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 ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 6 , 4 , 5 } ; int N = arr . length ; int P = 7 ; System . out . println ( equvInverse ( arr , N , P ) ) ; } }