online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <time.h> #include <algorithm> #define ll long long #define mod 998244353 using namespace std; ll bruteForce(ll x, ll y, ll l, ll r) { ll ans = (x & l) * (y & l); ll a = l; for (ll i = l;i <= r;i++) { ll k = ((x & i) * (y & i)); if (k > ans) { a = i;ans = k; } } return a; } ll vis(ll X, ll Y, ll L, ll R) { if (min(X, Y) == 0) return min(L, R); ll product = 0; ll ans = ((X & R) | (Y & R)); product = ((R & X) * (R & Y)); ll big = max(X, Y); ll small = min(X, Y); if (product == 0) ans = min(L, R); while (R > 0) { int right = (R ^ (R & (R - 1))); R -= right; int l = R; l += (right - 1);// this is the number of interest // cout << l << "\n"; ll temp = ((l & X) * (l & Y)); if ((temp == product) && l != 0) { product = temp; ll a = l & X; ll b = l & Y; ll o = (a | b); ans = min(ans, o); } if ((temp > product) && l != 0) { product = temp; ll a = l & X; ll b = l & Y; ans = (a | b); } ll g = l & big; ll h = l & small; if ((g == big) && (h == small)) break; } // cout << "\n"; return ans; } int main() { int t = 1; srand(time(0)); while (t) { ll L = 0; ll R = rand() % 10000; ll X = rand() % 10000; ll Y = rand() % 10000; cout << "testing for " << X << " " << Y << " " << L << " " << R << "\n"; if (vis(X, Y, L, R) != (bruteForce(X, Y, L, R))) { cout << "found a conflict!!" << "\n"; cout <<"my code gives"<< vis(X, Y, L, R) << "\n"; cout <<"brute force gives "<< bruteForce(X, Y, L, R) << "\n"; cout << X << " " << Y << " " << L << " " << R << "\n"; t = 0; } } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue