結果

問題 No.800 四平方定理
ユーザー UekiUeki
提出日時 2019-03-17 23:19:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,356 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 257,492 KB
最終ジャッジ日時 2023-09-22 10:49:05
合計ジャッジ時間 32,713 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 RE -
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 -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 76 ms
71,564 KB
testcase_21 RE -
testcase_22 WA -
testcase_23 TLE -
testcase_24 WA -
testcase_25 TLE -
testcase_26 AC 76 ms
71,500 KB
testcase_27 RE -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
import bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, D = map(int, input().split())


L = [v**2 for v in range(1, N+1)]
LIM = N**2+D


def fact(n):
    if n == 3:
        return 6
    elif n == 2:
        return 3
    else:
        return 1


def solve2():
    left = [x+y for x in L for y in L]
    left = sorted(left)
    ans = 0
    for w in L:
        for z in L:
            tmp = w-z+D
            ind = bisect.bisect_left(left, tmp)
            if left[ind] == tmp:
                rt = sqrt(tmp/2)
                if rt == int(rt):
                    ans += 1
                else:
                    ans += 2
    print(ans)


def solve1():
    ans = 0
    for x in range(1, N+1):
        tmp1 = x**2
        if tmp1 > LIM:
            break
        for y in range(x, N+1):
            tmp2 = tmp1+y**2
            if tmp2 > LIM:
                break
            for z in range(y, N+1):
                tmp3 = tmp2 + z**2
                if tmp3 > LIM:
                    break
                r = tmp3-D
                if r <= 0:
                    continue
                else:
                    rt = sqrt(r)
                    if rt <= N and rt == int(rt):
                        ans += fact(len(set([x, y, z])))
    print(ans)


# solve1()
solve2()
0