Skip to content
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

[bug] Primtive Root Function is Slow and Wrong for n=2. #43

Open
ongyiumark opened this issue Nov 16, 2023 · 0 comments
Open

[bug] Primtive Root Function is Slow and Wrong for n=2. #43

ongyiumark opened this issue Nov 16, 2023 · 0 comments
Assignees

Comments

@ongyiumark
Copy link
Contributor

As the title says. Our primitive root functons outputs -1 for n=2. 1 is actually a primitive root of 2, so the answer should be 1.

Also, we can speed it up because we don't actually need all the divisors of m-1, i.e., the totient function of m (because we're assuming m is prime). We just need the prime factors of m-1.

We can use an optimized $O(\sqrt{m})$ algo to factorize, which would have the same worst-case complexity, but would be much faster than getting all the divisors. The code also won't change very much.

For best speed up, we can use pollard's rho to factorize (but may be unnecesary for most cases).

@ongyiumark ongyiumark self-assigned this Nov 16, 2023
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

No branches or pull requests

1 participant