Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- long long sum(long long n)
- {
- if (n == 0) return 0;
- if (n%2 == 0)
- return n/2 * n/2 + sum(n/2);
- else
- return (n+1)/2 * (n+1)/2 + sum(n/2);
- }
- int main() {
- long long a, b,t;
- cin >> t;
- while (t>=0)
- {
- cin >> a >> b;
- cout << sum(b) - sum(a-1) << endl;
- t--;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement