992C - Nastya and a Wardrobe - CodeForces Solution


math *1600

Please click on ads to support us..

Python Code:

x, k = map(int,input().split())
print((1+(2*x-1)*pow(2,k,10**9+7))%(10**9+7) if x>0 else 0)

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mp make_pair 
#define p pair
#define vl vector<long long>
#define fr(i,a,b) for((i)=(a);(i)<=(b);(i)++)
#define rep(j,b) for((j)=0;(j)<(b);(j)++)
#define F first
#define S second
#define pb push_back
#define Y cout<<"YES\n";
#define N cout<<"NO\n";
#define all(v) (v).begin(), (v).end() 
#define Sort(v) sort(all(v))
#define mod 1000000007
#define M LLONG_MAX
#define nl cout<<endl;
//ll dp[1e5 +1];
ll binary_exponetiation(ll a, ll b)
{
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a) %mod;
        //res%=mod;
        a = a * a; a%=mod;
        b >>= 1;
    }
    return res;
}

vl input_vec(ll n) { ll i,a; vl vec; rep(i,n) { cin>>a; vec.pb(a); } return vec; }

void solve()
{
    ll plus=0, minus=0, minn,maxx,left=0, right=1,a,b,z,ans=0;
    ll n,c,q,h,k, m,i=0,j=2,w,index=0,x=0,y,d,sum=0,mid,cnt=0,temp;
    cin>>x>>k;
    if(x==0) {cout<<0<<endl; return; }
    ans= (((binary_exponetiation(2,k+1)%mod)*(x%mod))%mod)- binary_exponetiation(2,k) +1;
    //cout<<max(ans,0LL)%mod<<endl;
    cout << (ans % mod + mod) % mod << endl;
    

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1; //cin>>t;
    while(t--)
        solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1173B - Nauuo and Chess
318B - Strings of Power
1625A - Ancient Civilization
864A - Fair Game
1663B - Mike's Sequence
448A - Rewards
1622A - Construct a Rectangle
1620A - Equal or Not Equal
1517A - Sum of 2050
620A - Professor GukiZ's Robot
1342A - Road To Zero
1520A - Do Not Be Distracted
352A - Jeff and Digits
1327A - Sum of Odd Integers
1276A - As Simple as One and Two
812C - Sagheer and Nubian Market
272A - Dima and Friends
1352C - K-th Not Divisible by n
545C - Woodcutters
1528B - Kavi on Pairing Duty
339B - Xenia and Ringroad
189A - Cut Ribbon
1182A - Filling Shapes
82A - Double Cola
45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe
1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence