MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / sieve

Function sieve

code/mathematics/summatory_phi.cpp:12–18  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10 ans += sp[i] * (n/i - max(done, n/(i+1)));
11 return mem[n] = n*(n+1)/2 - ans; }
12void sieve() {
13 for (int i = 1; i < N; i++) sp[i] = i;
14 for (int i = 2; i < N; i++) {
15 if (sp[i] == i) {
16 sp[i] = i-1;
17 for (int j = i+i; j < N; j += i) sp[j] -= sp[j] / i; }
18 sp[i] += sp[i-1]; } }
19// vim: cc=60 ts=2 sts=2 sw=2:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected