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.


Cornachia's algorithm

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::cornacchia(a, b, m)


numlib::cornacchia(a, b, m) returns all pairs of positive and relatively prime integers x, y that solve the equation ax2 + by2 = m.

The arguments a, b, m must be pairwise relatively prime.


Example 1

We compute the solutions to 3 x2 + 5 y2 = 74533332452454382449233:

numlib::cornacchia(3, 5, 74533332452454382449233)

Example 2

For non-prime m, there may be many solutions:

numlib::cornacchia(1, 4, 5*13*17*29*73)



A positive integer


A positive integer


A positive integer

Return Values

numlib::cornacchia returns a set each element of which is a list of two positive integers.

See Also

MuPAD Functions

Was this topic helpful?