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

[Speculative] Tried replacing phiFunction with linear sieve that can calculate mobius as well. #171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Chillee
Copy link
Collaborator

@Chillee Chillee commented Apr 14, 2020

Not sure I like it. There might be other better/more general ways of calculating multiplicative functions. On the other hand, if we're including mobius inversion I think it makes sense to have a way of calculating the mobius function.

@simonlindholm
Copy link
Member

Seems kinda non-obvious how to change. I think a useful primitive might be a sieve that computes the smallest (or largest) prime that divides every number. Then it would be easy to compute phi:

rep(a,2,n) {
  int p = smallestPrimeDivisor[a], b = a / p;
  phi[a] = phi[b] * (p - (smallestPrimeDivisor[b] != p));
}

This may be too easy to code by hand to be worth including though.

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

Successfully merging this pull request may close these issues.

2 participants