結果

問題 No.3473 AtCoder < CMS
コンテスト
ユーザー tobisatis
提出日時 2026-03-20 22:00:06
言語 C#
(.NET 10.0.102)
コンパイル:
dotnet_c
実行:
/usr/bin/dotnet_wrap
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 4,214 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,593 ms
コンパイル使用メモリ 170,704 KB
実行使用メモリ 201,464 KB
最終ジャッジ日時 2026-03-20 22:00:15
合計ジャッジ時間 8,085 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (87 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

#nullable enable

#region
var (_input, _iter) = (Array.Empty<string>(), 0);
T I<T>() where T : IParsable<T>
{
    while (_iter >= _input.Length) (_input, _iter) = (Console.ReadLine()!.Trim().Split(' '), 0);
    return T.Parse(_input[_iter++], null);
}
#endregion

static T[] Range<T>(int n, Func<T> F) => Enumerable.Range(0, n).Select(_ => F()).ToArray();

static long Solve(long n, long m)
{
    ModInt c2 = 2;
    var n2 = c2.Power(n);
    var m2 = c2.Power(m);
    var im2 = m2.Power(-1);
    var nm2 = c2.Power(n * m);
    return nm2 * (1 - im2).Power(n) - nm2 + (n2 - 1).Power(m);
}

var t = I<int>();
var ans = Range(t, () => Solve(I<long>(), I<long>()));
Console.WriteLine(string.Join(Environment.NewLine, ans));

readonly record struct ModInt
{
    public const int Mod = 998244353;
    int V { get; init; }
    public ModInt(long value)
    {
        var v = value % Mod;
        if (v < 0) v += Mod;
        V = (int)v;
    }
    static ModInt New(int value) => new(){ V = value };

    public static implicit operator ModInt(long v) => new(v);
    public static implicit operator int(ModInt modInt) => modInt.V;

    public static ModInt AdditiveIdentity => New(0);
    public static ModInt operator +(ModInt a, ModInt b)
    {
        var v = a.V + b.V;
        if (v >= Mod) v -= Mod;
        return New(v);
    }
    public ModInt AdditiveInverse()
    {
        if (V == 0) return AdditiveIdentity;
        return New(Mod - V);
    }
    public static ModInt operator -(ModInt a, ModInt b)
    {
        var v = a.V - b.V;
        if (v < 0) v += Mod;
        return New(v);
    }

    public static ModInt MultiplicativeIdentity => New(1);
    public static ModInt operator *(ModInt a, ModInt b) => New((int)((long)a.V * b.V % Mod));
    public ModInt MultiplicativeInverse() => V == 0 ? throw new DivideByZeroException() : Power(V, Mod - 2, Mod);
    public static ModInt operator /(ModInt a, ModInt b) => a * b.MultiplicativeInverse();

    static long Power(long v, ulong p, long mod)
    {
        var (res, k) = (1L, v);
        while (p > 0)
        {
            if ((p & 1) > 0) res = res * k % mod;
            k = k * k % mod;
            p >>= 1;
        }
        return res;
    }
    public ModInt Power(long p) => p < 0 ? MultiplicativeInverse().Power(-p) : Power(V, (ulong)p, Mod);

    public override string ToString() => V.ToString();
}

static class FactorialExtensions
{
    public static ModInt Factorial(this int value)
    {
        Extend(value);
        return value < 0 ? _inv[-value] : _fac[value];
    }
    public static ModInt P(this int n, int r)
    {
        if (r < 0 || r > n) return 0;
        if (n <= MaxN) return Factorial(n) * Factorial(r - n);
        ModInt res = 1;
        for (var i = 0; i < r; i++) res *= n - i;
        return res;
    }
    public static ModInt C(this int n, int r)
    {
        if (r < 0 || r > n) return 0;
        r = Math.Min(r, n - r);
        return P(n, r) * Factorial(-r);
    }
    public static ModInt H(this int n, int r) => C(r + n - 1, r);

    public static ModInt ModIntInverse(this int n)
    {
        if (n == 0) throw new DivideByZeroException();
        if (n < 0) return ModIntInverse(-n).AdditiveInverse();
        if (n > MaxN) return ((ModInt)n).MultiplicativeInverse();
        return Factorial(n - 1) * Factorial(-n);
    }

    // [x^k](1-x)^-n = nHk
    public static ModInt[] NegativeBinomialSeries(long n, int m)
    {
        var res = new ModInt[m + 1];
        res[0] = 1;
        for (var i = 1; i <= m; i++) res[i] = res[i - 1] * (n - 1 + i) * ModIntInverse(i);
        return res;
    }

    const int MaxN = (1 << 24) - 1;
    static ModInt[] _fac = new ModInt[]{ 1 };
    static ModInt[] _inv = new ModInt[]{ 1 };
    static void Extend(int q)
    {
        var l = _fac.Length;
        if (q < 0) q = -q;
        if (q < l || MaxN < q) return;
        while (l <= q) l <<= 1;
        var fac = new ModInt[l];
        var inv = new ModInt[l];
        fac[0] = 1;
        for (var i = 1; i < fac.Length; i++) fac[i] = fac[i - 1] * i;
        inv[l - 1] = fac[l - 1].Power(-1);
        for (var i = inv.Length - 1; i > 0; i--) inv[i - 1] = inv[i] * i;
        (_fac, _inv) = (fac, inv);
    }
}
0