Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Number Theory/EulerTotientFunction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<bits/stdc++.h>
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";
}
}
Binary file added Number Theory/EulerTotientFunction.exe
Binary file not shown.
Binary file added Number Theory/EulerTotientFunction.o
Binary file not shown.