#include using namespace std; using LL = long long; int main() { // 1. 入力情報取得. LL N; cin >> N; // 2. 1 の 個数 を 計算. // Binary Pascal Triangle // https://mvtrinh.wordpress.com/2015/02/05/binary-pascal-triangle/ // -> N を 2進数で表現した場合の 1 の個数 を one と置くと, // Binary Pascal Triangle の N段目 の 1の個数 は, 2 の one乗 との内容が記載されている. LL one = 0, tN = N; do{ if(tN & 1) one++; }while(tN /= 2); // cout << "N=" << N << " one=" << one << endl; // Binary Pascal Triangle の N段目 の 1の個数 を 計算. LL bptOne = 1; while(one--) bptOne <<= 1; // cout << "bptOne=" << bptOne << endl; // 3. 出力 ~ 後処理. // Binary Pascal Triangle の N段目 の 0の個数 を 計算し, 出力. // ex. // N = 10 の場合, 10100000101 なので, -> bptZero = 7 のはず. // N = 1000000000000000000 の 場合, bptZero = 999999999983222785 で OK ???. LL bptZero = (N + 1) - bptOne; cout << bptZero << endl; return 0; }