Euler 's criterion (Check if square root under modulo p exists) | Returns true if square root of n under modulo p exists ; One by one check all numbers from 2 to p - 1 ; Driver Code
function squareRootExists ( n , p ) { n = n % p ; for ( let x = 2 ; x < p ; x ++ ) if ( ( x * x ) % p == n ) return true ; return false ; } let p = 7 ; let n = 2 ; if ( squareRootExists ( n , p ) === true ) document . write ( " " ) ; else document . write ( " " ) ;