325B - Stadium and Games - CodeForces Solution


binary search math *1800

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;

#define rep(i,a,b) for(int i=a;i<b;++i) 

#define pii pair<int,int>

#define all(x) x.begin(),x.end()

#define ff first

#define ss second



set<ll> st;

ll y;



void fun(ll b,ll i)

{

    //ll disc = (ll)sqrt(b*1*1.0 + 8*y);

    ll s = (ll)sqrt(b*1.0*b + 8*y);

    if(s<b) return;

    ll x = (s-b)/2;

    if(!(x&1)) return;

    while(i--)

    x*=2;

    ll t=x,sum=0;

    while(1)

    {

        if(t&1)

        {

            sum+=(t*(t-1))/2;

            break;

        }

        sum+=(t/2);

        t/=2;

    }

    if(sum==y) st.insert(x);

}





int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cin>>y;

    for(ll i=0;i<=62;++i)

    {

        ll t = ((1LL<<i)-1);

        fun(2*t-1,i);

    }

    if(st.empty())

    cout<<"-1\n";

    for(ll i:st)

    cout<<i<<"\n";

}


Comments

Submit
0 Comments
More Questions

1716A - 2-3 Moves
1670B - Dorms War
1716B - Permutation Chain
987A - Infinity Gauntlet
1676G - White-Black Balanced Subtrees
1716D - Chip Move
1352F - Binary String Reconstruction
1487B - Cat Cycle
1679C - Rooks Defenders
56A - Bar
1694B - Paranoid String
35A - Shell Game
1684A - Digit Minimization
43B - Letter
1017A - The Rank
1698B - Rising Sand
235A - LCM Challenge
1075B - Taxi drivers and Lyft
1562A - The Miracle and the Sleeper
1216A - Prefixes
1490C - Sum of Cubes
868A - Bark to Unlock
873B - Balanced Substring
1401D - Maximum Distributed Tree
1716C - Robot in a Hallway
1688B - Patchouli's Magical Talisman
99A - Help Far Away Kingdom
622B - The Time
1688C - Manipulating History
1169D - Good Triple