Skip to content

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

Open
Chillee wants to merge 1 commit into
kth-competitive-programming:mainfrom
Chillee:phi
Open

[Speculative] Tried replacing phiFunction with linear sieve that can calculate mobius as well.#171
Chillee wants to merge 1 commit into
kth-competitive-programming:mainfrom
Chillee:phi

Conversation

@Chillee

@Chillee Chillee commented Apr 14, 2020

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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