Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int maxN = 1e5;
- int64_t phi[maxN];
- void preComputePhi () {
- for (int i = 1; i < maxN; ++i) phi[i] = i;
- for (int i = 2; i < maxN; ++i) {
- if (phi[i] == i) {
- //i is a prime number
- //we need to subtract 1 from phi[i] because we know that phi[p] = p - 1
- for (int j = i; j < maxN; j += i) {
- phi[j] -= phi[j] / i;
- }
- }
- }
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T = 1;
- //~ cin >> T;
- preComputePhi();
- for (int test_case = 1; test_case <= T; ++test_case) {
- for (int i = 1; i < 30; ++i) {
- cout << phi[i] << ' ';
- }
- }
- //cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement