https://codeforces.com/contest/1236/problem/B
看代码即可,复制过来有些乱
B. Alice and the List of Presents
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.

There are nn kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.

Also, there are mm boxes. All of them are for different people, so they are pairwise distinct (consider that the names of mm friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.

Alice wants to pack presents with the following rules:

  • She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of nn kinds, empty boxes are allowed);
  • For each kind at least one present should be packed into some box.

Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 109+7109+7.

See examples and their notes for clarification.

Input

The first line contains two integers nn and mm, separated by spaces (1n,m1091≤n,m≤109) — the number of kinds of presents and the number of boxes that Alice has.

Output

Print one integer  — the number of ways to pack the presents with Alice's rules, calculated by modulo 109+7109+7

Examples
input
Copy
1 3
output
Copy
7
input
Copy
2 2
output
Copy
9
Note

In the first example, there are seven ways to pack presents:

{1}{}{}

{}{1}{}

{}{}{1}

{1}{1}{}

{}{1}{1}

{1}{}{1}

{1}{1}{1}

In the second example there are nine ways to pack presents:

{}{1,2}

{1}{2}

{1}{1,2}

{2}{1}

{2}{1,2}

{1,2}{}

{1,2}{1}

{1,2}{2}

{1,2}{1,2}

For example, the way {2}{2} is wrong, because presents of the first kind should be used in the least one box.

 

解:

The answer is (2^m1)^n

If we consider each present, it may contain only in the first box, in the second ... both in the first and second box, in the first and the third one ... in the first,the second and the third one ... There are 2^m1ways.

There are nn presents, so there are (2^m1)^ways in total according to the Multiplication Principle.

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T>
void out(T x) { cout << x << endl; }
ll fast_pow(ll a, ll b, ll p) {ll c = 1; while(b) { if(b & 1) c = c * a % p; a = a * a % p; b >>= 1;} return c;}
const ll mod = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    ll ans = (fast_pow(2, m, mod) - 1 + mod) % mod;
    ans = fast_pow(ans, n, mod) % mod;
    cout << ans << endl;
}