Problem 1215. Diophantine Equations (Inspired by Project Euler, problem 66)
Consider the quadratic Diophantine equation of the form:
x^2 – Dy^2 = 1
When D=13, the minimal solution in x is 649^2 – 13×180^2 = 1. It can be assumed that there are no solutions in positive integers when D is square.
Given a value of D, find the minimum value of X that gives a solution to the equation.
Solution Stats
Problem Comments
-
6 Comments
How exactly does, "6492 – 13×1802 = 1", as given in the example?
The 2s at the end of 649 and 180 used to be superscripts. I'm not quite sure when that changed, but it is fixed now. Thanks for the heads up on that.
No problem. Thanks for the fix!
Some tips. Continued fractions are the main way for finding the fundamental solutions to Pell's equations. And square roots have patterns in continued fractions.
Hi, I found the solution by using the continued fraction method and symbolic math.
The solution is faster and accurate in Matlab (0.214 secs for diophantine 12000).
This is the beginning of the function:
function minX = Diophantine_sym(D)
% Solve x^2 - D*y^2 = 1 using symbolic integers
a0 = floor(sqrt(D));
if a0^2 == D
minX = sym(0);
return
end
Unfortunately, the function is on error on cody site as the sym is not accepted. Do you know how can we abilitate the sym function on cody, or, as alternative, how can I publish my solution and avoid this error?
Thank you
@Sergio - MATLAB Cody does not support Toolboxes (which is mentioned in the Help page of Cody).
So (unfortunately) you won't be able to use sym() and related Symbolic toolbox functions/functionalities. You will have to utilize the basic MATLAB resources available to solve this (and all the other Cody) problem(s), as others have done.
Though, I am not sure why you need to state sym(0) instead of just 0?
Solution Comments
Show comments
Problem Recent Solvers69
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!