QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#685641#6425. Harmonious RectanglexjunRE 0ms3944kbC++201.8kb2024-10-28 20:33:222024-10-28 20:33:24

Judging History

你现在查看的是最新测评结果

  • [2024-10-28 20:33:24]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3944kb
  • [2024-10-28 20:33:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int n, m;

ll mod_mul(ll a, ll b, ll n) {
    a %= n;  //优化后只要在开头模一次,其他的地方用if,效率提升近一倍
    b %= n;
    ll res = 0;
    while (b) {
        if (b & 1) {
            res += a;
            if (res > n) res -= n;
        }
        a += a;
        if (a > n) a -= n;
        b /= 2;  //没开o2的话要换成b>>=1
    }
    return res;
}

ll mod_exp(ll a, ll b, ll n) {
    ll res = 1;
    a = a % n;
    while (b) {
        if (b & 1) res = mod_mul(res, a, n);
        a = mod_mul(a, a, n);
        b /= 2;
    }
    return res;
}

ll dat[9][9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 15, 339, 4761, 52929, 517761, 4767849, 43046721, 387420489,
0, 339, 16485, 518265, 14321907, 387406809, 460338013, 429534507, 597431612,
0, 4761, 518265, 43022385, 486780060, 429534507, 792294829, 175880701, 246336683,
0, 52929, 14321907, 486780060, 288599194, 130653412, 748778899, 953271190, 644897553,
0, 517761, 387406809, 429534507, 130653412, 246336683, 579440654, 412233812, 518446848,
0, 4767849, 460338013, 792294829, 748778899, 579440654, 236701429, 666021604, 589237756,
0, 43046721, 429534507, 175880701, 953271190, 412233812, 666021604, 767713261, 966670169,
0, 387420489, 597431612, 246336683, 644897553, 518446848, 589237756, 966670169, 968803245 };

int main() {
    int T;
    cin >> T;
    while (T--) {
        cin >> n >> m;
        if (n == 1 || m == 1) {
            printf("0\n");
        }
        else if (n <= 9 || m <= 9) {
            n--;
            m--;
            printf("%lld\n", dat[n][m] % MOD);
        }
        else {
            printf("%lld\n", mod_exp(3, 1LL * n * m, MOD));
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3944kb

input:

3
1 4
2 2
3 3

output:

0
15
16485

result:

ok 3 number(s): "0 15 16485"

Test #2:

score: -100
Runtime Error

input:

10000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 6...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
15
339
4761
52929
517761
4767849
43046721
387420489
0
339
16485
518265
14321907
387406809
46033801...

result: