B. Ralph And His Magic Field
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The only line contains three integers nm and k (1 ≤ n, m ≤ 1018k is either 1 or -1).

Output

Print a single number denoting the answer modulo 1000000007.

Examples
input
Copy
1 1 -1
output
Copy
1
input
Copy
1 3 1
output
Copy
1
input
Copy
3 3 -1
output
Copy
16
Note

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.



思路:打表.wa在了16.当我发现BUG改掉的时候,又wa了. vp结束了,一看代码.卧操~check把1放在外面了.崩溃

1. 看到1e18 能打表打表

2. 规律题总是看不出规律. MDZZ

#include<bits/stdc++.h>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;

const int N=1e5+5;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;

char s[200];
int n,m,k,ans;
int a[50][50];

bool check(){

//    for(int i=1;i<=n;i++){
//        for(int j=1;j<=m;j++) printf("%d ",a[i][j]);
//        puts("");
//    }
//    printf("***********");
    ll t;
    for(int i=1;i<=n;i++){
            t=1;
        for(int j=1;j<=m;j++) t*=a[i][j];
        if(t!=k)    return false;
    }
    for(int j=1;j<=m;j++){
        t=1;
        for(int i=1;i<=n;i++) t*=a[i][j];
        if(t!=k)    return false;
    }
//    printf("GOOD\n");
    return true;
}

void dfs(int x,int y){
    if(x==n&&y==m){
        a[x][y]=1;
        if(check()) ans++;
        a[x][y]=-1;
        if(check()) ans++;
//        puts("!**********");
        return ;
    }
    for(int t=1;t<=2;t++){
        if(t==1){
            a[x][y]=1;
            int xx=x,yy=y;
            if(m==yy) yy=1,xx++;
            else    yy++;
            dfs(xx,yy);
        }
        else{
            a[x][y]=-1;
            int xx=x,yy=y;
            if(m==yy) yy=1,xx++;
            else    yy++;
            dfs(xx,yy);
        }
    }

}

int main(void){
    for(n=1;n<=5;n++){
        for(m=1;m<=5;m++){
            ans=0;
            k=-1;
            dfs(1,1);
            printf("%d %d %d\n",n,m,ans);
        }
    }
    return 0;
}
/*********

*********/

#include<bits/stdc++.h>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;

const int N=1e5+5;
const ll MOD=1e9+7;
const int INF=0x3f3f3f3f;

ll qm(ll a,ll b){
    ll t=1;
    while(b){
        if(b&(1ll)) t=(t%MOD*a%MOD)%MOD;
        a=(a%MOD*a%MOD)%MOD;
        b>>=1ll;
    }
    return t%MOD;
}

int main(void){
    ll n,m,k;
    cin >>n>>m>>k;
//    if(n==1 || m==1){
//        cout << 1 << endl;
//        return 0;
//    }
    if(n%2==1 && m%2==0 && k==-1){
        cout <<0;return 0;
    }
    if(n%2==0 && m%2==1 && k==-1){
        cout <<0;return 0;
    }
    ll ans=qm(2,n-1)%MOD;
    ans=qm(ans,m-1)%MOD;
    cout << ans%MOD <<endl;
    return 0;
}
/*********

*********/