Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <unordered_map>
- #include <vector>
- #include<cmath>
- using namespace std;
- /*const int N = 100000;
- typedef long long ll;
- struct dt {
- unordered_map <ll, bool> m;
- int add;
- };
- int n;
- vector<ll> a;
- vector<dt> t;
- void build(vector<ll> &a, int v, int tl, int tr)
- {
- if (tl == tr) {
- t[v].m[a[tl]] = true;
- t[v].add = 0;
- }
- else {
- int tm = (tl + tr) >> 1;
- build(a, v << 1, tl, tm);
- build(a, (v << 1) + 1, tm + 1, tr);
- t[v] = t[v << 1];
- for (auto i : t[(v << 1) + 1].m)
- t[v].m[i.first] += i.second;
- }
- }
- void update(int pos, int new_val)
- {
- int v = 1;
- for (int tl = 0, tr = n - 1, tm; v < n << 2 && tl != tr;)
- {
- tm = (tl + tr) >> 1;
- if (pos <= tm) {
- v <<= 1;
- tr = tm;
- }
- else {
- v = (v << 1) + 1;
- tl = tm + 1;
- }
- }
- ll old_val = t[v].m.begin()->first;
- t[v].m.clear();
- t[v].m[new_val] = 1;
- for (v >>= 1; v > 0; v >>= 1) {
- t[v][old_val]--;
- if (t[v][old_val] == 0)
- t[v].erase(old_val);
- t[v][new_val]++;
- }
- }
- int freq(int v, int tl, int tr, int l, int r, int x)
- {
- if (l > r)
- return 0;
- if (l == tl && r == tr) {
- if (t[v][x] == 0) {
- t[v].erase(x);
- return 0;
- }
- return t[v][x];
- }
- else {
- int tm = (tl + tr) >> 1;
- return freq(v << 1, tl, tm, l, min(r, tm), x)
- + freq((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r, x);
- }
- }
- int gcd(int a, int b) {
- if (b == 0)
- return a;
- if (a == 0)
- return b;
- while (b) {
- a %= b;
- swap(a, b);
- }
- return a;
- }
- */
- typedef long long ll;
- unordered_map<ll, ll> memo;
- ll f(ll n, ll m)
- {
- ll res;
- if (memo.count(n) == 1)
- return memo[n];
- if (n % 2 == 1)
- res = f(n >> 1, m) * f((n >> 1) + 1, m) << 1 % m;
- else
- res = f(n >> 1, m) * f(n >> 1, m) % m;
- return res;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- long long n;
- memo[1] = 1;
- cin >> n;
- cout << f(n, (ll)1e+9 + 7LL) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement