Submission #531027

#TimeUsernameProblemLanguageResultExecution timeMemory
531027k777Rack (eJOI19_rack)C++14
100 / 100
4 ms312 KiB
#include <iostream>

using namespace std;
typedef long long ll;
const ll my_m = 1e9 + 7;

ll szy_po(ll a, ll x)
{
	if (x <= 0)
		return 1;
	if (x == 1)
		return a;
	if (x % 2 == 0)
		return (szy_po(a, x / 2) * szy_po(a, x / 2)) % my_m;
	return (szy_po(a, x / 2) * szy_po(a, x / 2 + 1)) % my_m;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n, k;
	ll p;
	ll v = 1;
	cin >> n >> k;
	--k;
	p = n;
	while (p--)
	{
		if (k % 2)
			v = (v * 2 + 1) % my_m;
		else
			v = (v * 2) % my_m;
		k /= 2;
	}
	cout << (v - szy_po(2, n) + 1 + my_m) % my_m << "\n";

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...