Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to k, where k is either 1 or -1.
Now Ralph wants you to figure out the number of ways to put numbers in each block in such a way that the magic field works properly. Two ways are considered different if and only if there exists at least one block where the numbers in the first way and in the second way are different. You are asked to output the answer modulo 1000000007 = 109 + 7.
Note that there is no range of the numbers to put in the blocks, but we can prove that the answer is not infinity.
The only line contains three integers n, m and k (1 ≤ n, m ≤ 1018, k is either 1 or -1).
Print a single number denoting the answer modulo 1000000007.
1 1 -1
1
1 3 1
1
3 3 -1
16
In the first example the only way is to put -1 into the only block.
In the second example the only way is to put 1 into every block.
题意:构造一个n*m的矩阵,使得矩阵每一行每一列的乘积都为K,K=+-1,求有多少种构造方法
找规律,每一行的数的乘积为k,一共有2^(m-1)种(假如k=1,C0k+C2k+C4k+....... +=2^(m-1),k=-1结果一样),n-1行的数可以任意填,只用最后一行来补就行,所以一共有(2^(n-1))^(m-1)种方法,当m+n为奇数且k=-1时,要特判0
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
#define pi acos(-1.0)
#define eps 1e-10
#define pf printf
#define sf scanf
#define lson rt<<1,l,mi
#define rson rt<<1|1,mi+1,r
#define it rt,l,r
#define root 1,1,n
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
ll m,n;
ll quick(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)ans=ans*x%mod;
y>>=1;
x=x*x%mod;
}
return ans;
}
int main()
{
int a;
while(cin>>m>>n>>a)
{
if((m+n)&1&&a==-1)
{
puts("0");
continue;
}
ll p=quick(quick(2,m-1),n-1);
pf("%I64d\n",p);
}
return 0;
}