arifin_fuad_kashfy's blog

By arifin_fuad_kashfy, history, 17 hours ago, In English

hellow, cf frined

u can go to my submission and check the last problem c in my submission, that has got ac, but how idk. Can anyone explain the right approach

I go to google;s xor calculator and input some values, find a pattern, and implement it with a random guess , and it has got AC :)

pls help,

Thanks in advance.:) here is it how it passed

»
17 hours ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

x-1 to 1??

  • »
    »
    15 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    nah vai oitha test er jonow contest shese didis contest time e aktha ac hosisilow ar age dharan link dei Your text to link here...

»
16 hours ago, # |
  Vote: I like it +1 Vote: I do not like it

if you know binary search, it was simple simulation, i dont know why so many people were worried to make bitwise operations on that!

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    how do you show monotonicity on the range of y?

    thanks

    • »
      »
      »
      3 hours ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      it was said y would lie from 1 to x-1, so that is our range, then we will check for mid, and see if x^mid < x+mid and x^mid > x-mid, if both conditions are satisfied it is a valid y, so print it, think about it, is much easier than what others did

»
15 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by arifin_fuad_kashfy (previous revision, new revision, compare).

»
3 hours ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

what is "__builtin_clz(x)": This counts the number of leading zeros in the binary representation of x.

eg:

If x = 5 (binary 101), the number of leading zeros is 29 (assuming a 32-bit integer, since 5 is 000xxx000101).

If x = 8 (binary 1000), the number of leading zeros is 28.

If x = 5 (binary 101), 32 — __builtin_clz(5) — 1 = 3 — 1 = 2.

If x = 8 (binary 1000), 32 — __builtin_clz(8) — 1 = 4 — 1 = 3.

TRY THIS CODE-->


#include <bits/stdc++.h> using namespace std; #define ll long long int binary_of_x(int x) { return (1 << (32 &mdash; __builtin_clz(x) &mdash; 1)) &mdash; 1; } void solve() { ll x; cin >> x; ll B = binary_of_x(x); ll xorB = x ^ B; ll a = B, b = xorB, c = x; if (a > c) { swap(a, c); } if (b > c){ swap(b, c); } if (a + b > c) { cout << B << "\n"; } else { cout << "-1\n"; } } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }