This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#define ll long long
#define pb push_back
#define F first
#define S second
#define ull unsigned long long
#define pii pair < int, int >
#define ld long double
using namespace std;
using namespace __gnu_pbds;
mt19937 gen(time(0));
template <typename T>
using ordered_set=tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n;
void Solve(ll k)
{
vector < ll > p;
vector < ll > bp;
bp.pb(1);
for (int i = 1; i <= n; i++) bp.pb((bp.back() * 2) % 1000000007);
for (int i = n - 1; i >= 1; i--)
{
p.pb(bp[i]);
}
ll ans = 1;
for (int i = 0; i < (int)p.size(); i++)
{
if ((1ll << i) > k) break;
ll kol = k / (1ll << i);
ll ost = k % (1ll << i);
if (kol % 2 == 1 && ost > 0)
ans = (ans + p[i]) % 1000000007;
else
if (kol % 2 == 0 && ost == 0)
ans = (p[i] + ans) % 1000000007;
}
if (n < 60 && k > (1ll << n) / 2) ans++;
cout << ans % 1000000007 << " ";
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#else
#endif
cin >> n;
ll k;
cin >> k;
// for (int i = 1; i <= k; i++)
// Solve(i);
Solve(k);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |