fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. long long n, h, contadivisori;
  5.  
  6. void contadiv(long long x) {
  7. contadivisori = 0;
  8. long long y = 1;
  9. h = 1;
  10. while (y <= static_cast<int64_t>(std::trunc(std::sqrt(x)))) {
  11. if (x % y == 0) {
  12. if (y != x / y)
  13. h += 2;
  14. else
  15. h += 1;
  16. }
  17. y++;
  18. }
  19. contadivisori = h - 1;
  20. }
  21.  
  22. long long compute(long long x) {
  23. long long i, somma = 0;
  24. for (i = 1; i <= n; i++) {
  25. contadiv(i);
  26. somma += contadivisori;
  27. }
  28. return somma;
  29. }
  30.  
  31. int main() {
  32. std::cin >> n;
  33. std::cout << compute(n) << std::endl;
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5312KB
stdin
5
stdout
10