codeforces E. Height All the Same

在这里插入图片描述

题目

思路:

博客)可以看篇博客,写的挺全,挺好的(偶尔偷下懒)。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
inline void out(ll x) {
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}
const int mod = 998244353;
ll quickpow(ll a, ll b) {
    ll ans = 1, base = a;
    while (b) {
        if (b & 1) ans = ans * base % mod;
        base = base * base % mod;
        b >>= 1;
    }
    return ans;
}
int main() {
    ll n, m, l, r;
    read(n), read(m), read(l), read(r);
    if (n * m % 2 == 1) out(quickpow(r - l + 1, n * m));
    else {
        ll x = r - l + 1;
        ll ans = (quickpow(x, n * m) + (x & 1)) * quickpow(2, mod - 2) % mod;
        out(ans);
    }
    return 0;
}

发布了463 篇原创文章 · 获赞 27 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_45031646/article/details/105295770