mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
parent
45c209072e
commit
4f6248c621
26
S2OJ/12/12.cpp
Normal file
26
S2OJ/12/12.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int t;
|
||||
long long n, s;
|
||||
|
||||
int main() {
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
cin >> n >> s;
|
||||
if (s) {
|
||||
cout << (n + 1 >> 1) << endl;
|
||||
} else if (n & 1) {
|
||||
cout << (n >> 1) << endl;
|
||||
} else {
|
||||
for (int i = 1; i <= 30; i++) {
|
||||
if ((1ll << (i - 1)) <= n && n < (1ll << i)) {
|
||||
cout << ((n - (1ll << i - 1)) >> 1) << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user