結果

問題 No.2847 Birthday Attack
ユーザー tobisatistobisatis
提出日時 2024-08-23 23:55:37
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 2,578 bytes
コンパイル時間 8,337 ms
コンパイル使用メモリ 167,372 KB
実行使用メモリ 193,160 KB
最終ジャッジ日時 2024-08-23 23:56:16
合計ジャッジ時間 37,469 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
29,148 KB
testcase_01 AC 49 ms
29,184 KB
testcase_02 AC 49 ms
29,184 KB
testcase_03 AC 948 ms
31,232 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (94 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

namespace AtCoder;

#nullable enable

using System.Numerics;

static class Extensions
{
    public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}

class AtCoder
{
    object? Solve()
    {
        var x = Int();
        var y = Int();
        var z = Math.Max(x, y);
        var m = Int();
        var ans = 0L;
        long GCD(long i, long j) => j == 0 ? i : GCD(j, i % j);
        long F(long a, long b)
        {
            Int128 t = Int128.MaxValue;
            if (a > 0)
            {
                var sx = x / a;
                if (sx < t) t = sx;
            }
            if (b > 0)
            {
                var sy = y / b;
                if (sy < t) t = sy;
            }
            var res = t * x * y % m;
            var t2 = t * (t + 1) * (t * 2 + 1) / 6 % m;
            var t1 = t * (t + 1) / 2 % m;
            res += t2 * a * b - t1 * (x * b + y * a);
            res %= m;
            if (res < 0) res += m;
            return (long)res;
        }
        for (var i = 0L; i <= z; i++) for (var j = 0L; j < i; j++)
        {
            if ((i + j) % 2 == 0) continue;
            var au = i * j * 2 * 2;
            var bu = (i * i - j * j) * 2;
            if (x < au && y < au && x < bu && y < bu) break;
            if (GCD(i, j) != 1) continue;
            ans = (ans + F(au, bu) + F(bu, au)) % m;
        }
        return ans * 2 % m;
    }

    public static void Main() => new AtCoder().Run();
    public void Run()
    {
        var res = Solve();
        if (res != null)
        {
            if (res is bool yes) res = yes ? "Yes" : "No";
            sw.WriteLine(res);
        }
        sw.Flush();
    }

    string[] input = Array.Empty<string>();
    int iter = 0;
    readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false };

    string String()
    {
        while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0);
        return input[iter++];
    }
    T Input<T>() where T : IParsable<T> => T.Parse(String(), null);
    int Int() => Input<int>();
    void Out(object? x, string? separator = null)
    {
        separator ??= Environment.NewLine;
        if (x is System.Collections.IEnumerable obj and not string)
        {
            var firstLine = true;
            foreach (var item in obj)
            {
                if (!firstLine) sw.Write(separator);
                firstLine = false;
                sw.Write(item);
            }
        }
        else sw.Write(x);
        sw.WriteLine();
    }
}
0