Permalink
Find file Copy path
d6d191c Oct 31, 2015
1 contributor

Users who have contributed to this file

16 lines (15 sloc) 270 Bytes
#include <cstdio>
int main() {
long long n;
long long sum = 0, k = 1;
scanf("%lld", &n);
for (int i = 0; i <= 58; i++) {
sum += n / (k * 2) * k;
if (n % (k * 2) >= k) {
sum += n % k + 1;
}
k *= 2;
}
printf("%lld\n", sum);
return 0;
}