text: Euler 's criterion (Check if square root under modulo p exists) | A Simple C # program to check if square root of a number under modulo p exists or not ; Returns true if square root of n under modulo p exists ; One by one check all numbers from 2 to p - 1 ; Driver code
code: using System ; class GFG { static bool squareRootExists ( int n , int p ) { n = n % p ; for ( int x = 2 ; x < p ; x ++ ) if ( ( x * x ) % p == n ) return true ; return false ; } public static void Main ( ) { int p = 7 ; int n = 2 ; if ( squareRootExists ( n , p ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }