【数学】Codeforces894B Ralph And His Magic Field

来源:互联网 发布:linux 查询连接ip 编辑:程序博客网 时间:2024/05/17 23:21

第一天掉分后十分不愉快,晚上一直没睡着,看着手机等终测结果,果不其然C变得鲜红鲜红的了。
于是决定两天后接着刚,想这一次冷静下来敲出C就好了,然后碰上送命场,B并没有那么水,C也没能冷静下来,摊手

题意:在一个长为n,宽为m的矩阵内填数,使得每一行,每一列的积为k。k等于1或-1;
题解:比赛时通过打表发现了一点规律,但是没能总结精炼。k=1时答案为
2^[(m-1)*(n-1)]
k=-1时,m+n为奇数时无解,偶数时与上面相同。

另外学到了一波欧拉定理;

#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<cstdio>#include<cstring>#include<set>using namespace std;typedef long long LL;const int maxn = 1000010;const int mod = 1000000007;LL Qpow(LL x, LL n){    LL res = 1, base = x;    while (n){        if (n & 1) res = res*base%mod;        base = base*base%mod;        n >>= 1;    }    return res;}int main(){    LL m, n, k;    cin >> n >> m >> k;    if (k == -1 && (m + n) % 2 == 1){        puts("0");        //system("pause");        return 0;    }    else{        LL tmp = Qpow(2, (m - 1));        tmp = Qpow(tmp, (n - 1));        cout << tmp << endl;        //system("pause");        return 0;    }}
阅读全文
0 0
原创粉丝点击