結果

問題 No.2847 Birthday Attack
ユーザー 👑 seekworser
提出日時 2024-07-09 23:01:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 524 ms / 3,000 ms
コード長 742 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 82,484 KB
実行使用メモリ 76,712 KB
最終ジャッジ日時 2024-07-09 23:01:51
合計ジャッジ時間 7,316 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd


x,y,md = map(int, input().split())

def calc_total(x) -> int:
    xk = x // 2
    xtotal = (xk + 1) * xk
    return (xk * x - xtotal) % md
ans = (calc_total(x) * 2 * y + calc_total(y) * 2 * x) % md
mx = max(x, y) // 2 + 1
for m in range(1, mx+1):
    for n in range(m+1, mx+1):
        if (m % 2 == n % 2) or gcd(m, n) != 1: continue
        ai = n*n - m*m
        bi = 2*m*n
        if (ai > mx) or (bi > mx): break
        mul = 1
        while (mul * max(ai, bi) <= mx):
            a = ai*mul
            b = bi*mul
            if a*2 < x and b*2 < y: ans = (ans + (x - 2*a) * (y - 2*b) * 4) % md
            if b*2 < x and a*2 < y: ans = (ans + (x - 2*b) * (y - 2*a) * 4) % md
            mul += 1
print(ans % md)
0