fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. const int N = 1e6 + 1;
  6. int p[N];
  7.  
  8.  
  9. void solve() {
  10.  
  11.  
  12. //Calculating factors using prime sieve
  13. for (int i = 2; i < N; ++i) {
  14. if (p[i])continue;
  15. for (int j = i; j < N; j += i)p[j] = i;
  16. }
  17. for (int i = 2; i < N; ++i) {
  18. if (p[i])continue;
  19. for (int j = i; j < N; j += i)p[j] = i;
  20. }
  21.  
  22. auto getFactorCnt = [&](int x) {
  23. int ans = 1;
  24. while (x > 1) {
  25. int prime = p[x], cnt = 1;
  26. while (x % prime == 0)cnt++, x /= prime;
  27. ans *= cnt;
  28. }
  29. return ans;
  30. };
  31.  
  32. //Main code
  33. int res = 0;
  34. int n; cin >> n;
  35. for (int i = 1; i < n; ++i)
  36. {
  37. res = res + getFactorCnt(n - i);
  38. }
  39.  
  40. cout << res << endl;
  41. }
  42.  
  43.  
  44.  
  45. int main() {
  46.  
  47.  
  48. #ifndef ONLINE_JUDGE
  49. freopen("input1.txt", "r", stdin);
  50. freopen("output1.txt", "w", stdout);
  51. #endif
  52.  
  53. // int t; cin >> t;
  54. int t = 1;
  55.  
  56. while (t--) {
  57. solve();
  58. }
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0.01s 7428KB
stdin
100
stdout
473