Skip to content

fix continued fraction sqrt code #962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 29, 2022
Merged

Conversation

bqi343
Copy link
Contributor

@bqi343 bqi343 commented Nov 26, 2022

The original code gives runtime error on n = 3. The updated code was tested on Tavrida NU Akai Contest - Continued Fraction.

@adamant-pwn
Copy link
Member

adamant-pwn commented Nov 29, 2022

Thanks for noticing! There is much simpler fix though (see my commits) :)

@adamant-pwn adamant-pwn merged commit 19c7a40 into cp-algorithms:master Nov 29, 2022
@bqi343
Copy link
Contributor Author

bqi343 commented Nov 29, 2022

it seems that the variable naming used in the solution is not consistent with the explanation though.

Also, I observed that (x + y*n0)//z == math.floor(x + y * math.sqrt(n)) // z always seems to hold for the given initialization of x, y, and z. Why is this the case? (It's not true if we are allowed to initialize x, y, and z arbitrarily.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants