HTML & JS
#include<bits/stdc++.h> 
using namespace std; 
#define max(a, b) (a < b ? b : a) 
#define min(a, b) ((a > b) ? b : a) 
typedef long long int ll;

ll power(ll x, ll y)
{
    ll res = 1;
    while (y > 0) {
        if (y % 2 == 0)
        {
            x = x * x;
            y = y / 2;
        }
        else
        {
            res = res * x;
            y = y - 1;
        }
    }
    return res;
}

ll solve(ll n,ll k)
{
    if(k==1)return n;
    int mx=floor(log2(n));
    return power(2,mx+1)-1;
}

int main() 
{ 
    ios::sync_with_stdio(0); 
    cin.tie(0);
    
        ll n,k;
        cin >> n >> k;
        
        cout<<solve(n,k);

    return 0; 
} 


Generated URL:

Output:

576460752303423487
Report Bug