Cod sursa(job #2357977)

Utilizator AlexPop28Pop Alex-Nicolae AlexPop28 Data 27 februarie 2019 20:41:38
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <bits/stdc++.h>
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define fi first
#define se second
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'

using namespace std;

typedef pair <int, int> pii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;

template <class T> void uin (T &a, T b) {a = min (a, b);}
template <class T> void uax (T &a, T b) {a = max (a, b);}

ifstream f ("fractii.in");
ofstream g ("fractii.out");

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEFINE
  freopen (".in", "r", stdin);
#endif

  int n;
  f >> n;
  vi phi (n + 2, 0);
  for (int i = 1; i <= n; ++i) {
    phi[i] = i;
  }
  ll ans = 0;
  for (int i = 2; i <= n; ++i) {
    for (int j = i, init = phi[i] == i; j <= n && init; j += i) {
      phi[j] /= i;
      phi[j] *= (i - 1);
    }
    ans += phi[i];
  }

  g << 2 * ans + 1 << '\n';

  f.close();
  g.close();

#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}