Created
December 5, 2018 16:53
-
-
Save Masud-Parves/f93c96dd493f97fe9ebdded1ce31a8bd to your computer and use it in GitHub Desktop.
Euler's Phi Function(Sieve).cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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