#pragma comment(linker, "/STACK:102400000,102400000") #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; set S; const int M = 62; long long p[M]; int maxFull; void solve(long long x, int h) { if(x == p[h] - 1) { maxFull = max(maxFull, h); return; } S.insert(x); long long ans = 0; int height = 0; x--; for(int i = 0; i < M; i++) { ans += p[i] * 2; if(x >= ans) height++; else break; } long long delta = x - (p[height] - 1) * 2; if(delta > p[height]) { long long L = p[height + 1] - 1; solve(L, height + 1); solve(x - L, height + 1); } else if(delta > 0) { long long L = p[height] - 1 + delta; solve(L, height + 1); solve(x - L, height); } else { solve(x / 2, height); } } int main() { for(int i = 0; i < M; i++) p[i] = 1LL << i; long long n; while(~scanf("%I64d", &n)) { long long ans = 0; int height = 0; maxFull = 0; for(int i = 0; i < M; i++) { ans += p[i]; if(n >= ans) height++; else break; } S.clear(); solve(n, height + (n > (p[height] - 1))); for(int i = 1; i <= maxFull; i++) { S.insert(p[i] - 1); } printf("%d\n", (int)S.size()); } return 0; }