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 program to test
code: #include <iostream> NEW_LINE using namespace std ; 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 ; } int main ( ) { int p = 7 ; int n = 2 ; squareRootExists ( n , p ) ? cout << " Yes " : cout << " No " ; return 0 ; }