fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void fileIO() {
  6. #ifndef ONLINE_JUDGE
  7. freopen("input.txt", "r", stdin);
  8. freopen("output.txt", "w", stdout);
  9. #endif
  10.  
  11. #ifdef ONLINE_JUDGE
  12. #endif
  13. }
  14.  
  15. int TC;
  16.  
  17. void get_shit_done() {
  18. long long n;
  19. cin >> n;
  20.  
  21. vector<long long> v;
  22. for (long long i = 1; i * i <= n; ++i) {
  23. if (n % i == 0) {
  24. v.push_back(i + n / i);
  25. }
  26. }
  27. sort(v.rbegin(), v.rend());
  28.  
  29. long long ans = 0;
  30. for (int i = 0; i + 1 < int(v.size()); ++i) {
  31. ans += v[i] - v[i + 1];
  32. }
  33.  
  34. cout << ans;
  35. }
  36.  
  37. signed main() {
  38. fileIO();
  39. cin.tie(nullptr);
  40. cout.tie(nullptr);
  41. ios::sync_with_stdio(false);
  42.  
  43. int T = 1;
  44. for (TC = 1; TC <= T; ++TC) {
  45. get_shit_done();
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.05s 5296KB
stdin
Standard input is empty
stdout
23145079278783