結果
| 問題 |
No.2847 Birthday Attack
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-23 23:55:37 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | WA * 14 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /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/
ソースコード
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();
}
}