diff --git a/Number Theory/EulerTotientFunction.cpp b/Number Theory/EulerTotientFunction.cpp new file mode 100644 index 0000000..dc0551f --- /dev/null +++ b/Number Theory/EulerTotientFunction.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; + +using ll = long long; + +const ll MAXN = 1000001; +int t; +ll n, phi[MAXN]; + +void seive() { + for (ll i = 1; i < MAXN; i++) phi[i] = i; + + for (ll i = 2; i < MAXN; i++) { + if (phi[i] == i) { + phi[i] = phi[i] - 1; + for (ll j = i * 2; j < MAXN; j += i) { + phi[j] = phi[j] - (phi[j] / i); + } + } + } +} + +int main() { + ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); + + seive(); + cin >> t; + while (t--) { + cin >> n; + cout << phi[n] << "\n"; + } +} diff --git a/Number Theory/EulerTotientFunction.exe b/Number Theory/EulerTotientFunction.exe new file mode 100644 index 0000000..1b24ce7 Binary files /dev/null and b/Number Theory/EulerTotientFunction.exe differ diff --git a/Number Theory/EulerTotientFunction.o b/Number Theory/EulerTotientFunction.o new file mode 100644 index 0000000..a7f0773 Binary files /dev/null and b/Number Theory/EulerTotientFunction.o differ