fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4.  
  5. unordered_map<int, int> memo;
  6.  
  7. int S(int n) {
  8. if (n == 0) return 0;
  9. if (memo.count(n)) return memo[n];
  10.  
  11. int ans = n * (n + 1) / 2;
  12. int i = 2;
  13. while (i <= n) {
  14. int q = n / i;
  15. int r = n / q;
  16. ans -= (r - i + 1) * S(q);
  17. i = r + 1;
  18. }
  19. return memo[n] = ans;
  20. }
  21.  
  22. main() {
  23. ios::sync_with_stdio(false);
  24. cin.tie(nullptr);
  25.  
  26. int N, D;
  27. cin >> N >> D;
  28.  
  29. int M = N / D;
  30. cout << S(M);
  31. }
  32.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty