Skip to content

Instantly share code, notes, and snippets.

@Masud-Parves
Created December 5, 2018 16:53
Show Gist options
  • Save Masud-Parves/f93c96dd493f97fe9ebdded1ce31a8bd to your computer and use it in GitHub Desktop.
Save Masud-Parves/f93c96dd493f97fe9ebdded1ce31a8bd to your computer and use it in GitHub Desktop.
Euler's Phi Function(Sieve).cpp
#define M 1000005
int phi[M]; // প্রতিটা ইনডেক্সে টশিয়ান্ট ভ্যালু রাখার জন্য array
void totientSieve() {
for (int i = 1; i < M; i++) {
phi[i] = i;
}
for (int p = 2; p < M; p++) {
if (phi[p] == p) { // এখানে p প্রাইম নাম্বার
for (int k = p; k < M; k += p) {
phi[k] -= phi[k] / p;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment