fork(1) download
  1. #include <cstdio>
  2. #include <unordered_map>
  3. #define lint long long
  4. #define MAX 0
  5.  
  6. lint phi[MAX];
  7. std::unordered_map<int, lint> mp;
  8.  
  9. lint S(int x) {
  10. int i, j;
  11. if (x < MAX) return phi[x];
  12. if (mp.find(x) != mp.end()) return mp[x];
  13. lint ret = x * (x + 1LL) / 2;
  14. for (i = 2; i <= x; i = j+1) {
  15. j = x / (x / i);
  16. ret -= (j - i + 1) * S(x / i);
  17. }
  18. return mp[x] = ret;
  19. }
  20.  
  21. int main()
  22. {
  23. int N, i, j;
  24. scanf("%d", &N);
  25.  
  26. for (i = 1; i < MAX; ++i) {
  27. phi[i] += i;
  28. for (j = 2; j*i < MAX; ++j) phi[j*i] -= phi[i];
  29. phi[i] += phi[i-1];
  30. }
  31.  
  32. printf("%lld", S(N));
  33. return 0;
  34. }
Success #stdin #stdout 1.22s 6140KB
stdin
1000000000
stdout
303963551173008414