Iamtui1010

perfectornot.cpp

Mar 9th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<vector>
  4.  
  5. #define long long long
  6. #define nln '\n'
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     cin.tie(0)->sync_with_stdio(0);
  13.     cout.tie(0)->sync_with_stdio(0);
  14.     //freopen("perfectornot.inp", "r", stdin);
  15.     long a, b;
  16.     cin >> a >> b;
  17.  
  18.     vector<long> s(b+1, 1);
  19.     s[1] = 0;
  20.     for (long i = 2; i <= b; ++i)
  21.         for (long j = 2*i; j <= b; j += i)
  22.             s[j] += i;
  23.  
  24.     long ans = 0;
  25.     for (long i = a; i <= b; ++i)
  26.         ans += abs(i-s[i]);
  27.     cout << ans << nln;
  28.  
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment