/* -*- coding: utf-8 -*- * * 737.cc: No.737 PopCount - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MOD = 1000000007; /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ ll powmod(ll a, int b) { ll pm = 1; while (b) { if (b & 1) pm = pm * a % MOD; a = a * a % MOD; b >>= 1; } return pm; } /* main */ int main() { ll n; scanf("%lld", &n); ll sum = 0, bk = 1; ll inv2 = powmod(2, MOD - 2); for (int k = 0; bk <= n; k++, bk <<= 1) { ll bk1 = bk << 1; ll div = n / bk1, rem = n % bk1; ll d0 = 0, d1 = 0, d2 = 0; d0 = (bk1 - 1 + bk) % MOD * bk % MOD * inv2 % MOD * div % MOD; if (div > 1) d1 = div % MOD * (div - 1) % MOD * inv2 % MOD * bk1 % MOD * bk % MOD; if (rem >= bk) d2 = (bk + rem) % MOD * (rem - bk + 1) % MOD * inv2 % MOD + div * bk1 % MOD * (rem - bk + 1) % MOD; //printf("k=%d: div=%lld, rem=%lld, d=(%lld,%lld,%lld)\n", //k, div, rem, d0, d1, d2); sum = (sum + d0 + d1 + d2) % MOD; } printf("%lld\n", sum); return 0; }