Skip to content

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

@ongyiumark

Description

@ongyiumark

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).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions