fork download
  1. #include <bits/stdc++.h>
  2.  
  3. typedef long long ll;
  4. using namespace std;
  5.  
  6. #define N 1000001
  7. int phi[N];
  8. ll a[N];
  9. #define GC getchar_unlocked()
  10. int scan() {
  11. int ret = 0;
  12. int ip = GC;
  13. for (; ip < '0' || ip > '9'; ip = GC)
  14. ;
  15. for (; ip >= '0' && ip <= '9'; ip = GC)
  16. ret = ret * 10 + ip - '0';
  17. return ret;
  18. }
  19.  
  20. int main() {
  21. int i, j, n;
  22. for (i = 1; i < N; i++)
  23. phi[i] = i;
  24. phi[1] = 0;
  25. for (i = 2; i < N; i++)
  26. if (phi[i] == i)
  27. for (j = i; j < N; j += i)
  28. phi[j] -= phi[j] / i;
  29. for (i = 1; i < N; i++) {
  30. for (j = i; j < N; j += i) {
  31. a[j] += (i * phi[(j / i)]);
  32. }
  33. }
  34. for (i = 2; i < N; i++)
  35. a[i] += a[i - 1];
  36. while (1) {
  37. n = scan();
  38. assert(n < N);
  39. if (n == 0)
  40. break;
  41. printf("%lld\n", a[n]);
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0.07s 15192KB
stdin
10
100
200000
0
stdout
67
13015
143295493160