From 523f43341f4420ef13e1c02612747f11c93d6fd5 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 24 Dec 2021 22:59:02 +0800 Subject: [PATCH] B - And It's Non-Zero https://codeforces.com/contest/1615/submission/140464543 --- CodeForces/1615/B/B.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 CodeForces/1615/B/B.cpp diff --git a/CodeForces/1615/B/B.cpp b/CodeForces/1615/B/B.cpp new file mode 100644 index 00000000..e6651903 --- /dev/null +++ b/CodeForces/1615/B/B.cpp @@ -0,0 +1,25 @@ +#include + +using std::cin; +using std::cout; +using std::endl; + +int t, l, r, b[200005][32]; + +int main() { + for (int i = 1; i < 200005; i++) { + for (int k = 0; k < 32; k++) { + b[i][k] = b[i - 1][k] + ((i >> k) & 1); + } + } + cin >> t; + while (t--) { + cin >> l >> r; + int max = 0; + for (int k = 0; k < 32; k++) { + max = std::max(max, b[r][k] - b[l - 1][k]); + } + cout << r - l + 1 - max << endl; + } + return 0; +}