ZOJ 4535 ZOJ Monthly, October 2011 H

  How Many Sets I Time Limit: 2 Seconds      Memory Limit: 65536 KB

Give a set S, |S| = n, then how many ordered set group (S1, S2, ..., Sk) satisfies S1 ∩ S2 ∩ ... ∩ Sk = ∅. (Si is a subset of S, (1 <= i <= k))

Input

The input contains multiple cases, each case have 2 integers in one line represent n and k(1 <= k <= n <= 231-1), proceed to the end of the file.

Output

Output the total number mod 1000000007.

Sample Input

1 1
2 2

Sample Output

1
9
 
整套比赛最简单的一个。
可以直接写一个暴力程序,然后找规律。
规律很显然的~
 
我的代码:
#include<stdio.h>
#include<iostream>

using namespace std;

typedef long long ll;

ll mod=1000000007;

ll power(ll p,ll n,ll m)
{
	ll sq=1;
	while(n>0)
	{
		if(n%2==1)
			sq=(sq%m)*(p%m)%m;
		p=(p%m)*(p%m)%m;
		n=n/2;
	}
	return sq%m;
}

int main()
{
	ll n,k,ans;
	while(cin>>n>>k)
	{
		ans=power(2,k,mod)-1;
		ans=power(ans,n,mod);
		cout<<ans<<endl;
	}
	return 0;
}


你可能感兴趣的:(input,each,output)