This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Square root of a quadratic residue modulo a prime

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


numlib::sqrtmodp(a, p)


numlib::sqrtmodp(a, p) computes a solution x to the congruence .

numlib::sqrtmodp(a, p) computes an integer x that satisfies .

a must be a quadratic residue modulo p, and p must be a prime. This is not checked! Unless this is known to be the case, numlib::msqrts must be used. On the other hand, numlib::sqrtmodp is faster than numlib::msqrts.


Example 1

One square root of 132132 modulo 3231227 is 3012020:




An integer


A prime unequal to 2

Return Values

numlib::sqrtmodp returns an integer.


numlib::sqrtmodp uses D. Shanks' algorithm RESSOL.

See Also

MuPAD Functions

Was this topic helpful?