結果

問題 No.800 四平方定理
ユーザー pasoconhoshiipasoconhoshii
提出日時 2019-03-17 22:54:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,358 bytes
コンパイル時間 1,295 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 82,436 KB
最終ジャッジ日時 2023-09-22 09:14:27
合計ジャッジ時間 9,977 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 252 ms
77,780 KB
testcase_01 AC 426 ms
77,600 KB
testcase_02 AC 327 ms
78,060 KB
testcase_03 AC 317 ms
77,696 KB
testcase_04 AC 277 ms
78,012 KB
testcase_05 AC 304 ms
78,008 KB
testcase_06 AC 526 ms
77,616 KB
testcase_07 AC 450 ms
78,112 KB
testcase_08 AC 858 ms
77,904 KB
testcase_09 AC 494 ms
78,176 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

lst = [i**2 for i in range(1, N+1)]

ans= 0
for i in range(N):
    x = lst[i]
    for j in range(N):
        y = lst[j]
        s = x+y-D

        # print("x,y, s: ", x,y,s)

        if s == 0:
            ans += N
            # print("equal get!")

        else:
            # $BLs?t%j%9%H(B
            divlst = []
            s = abs(s)

            for div in range(1, int(s**0.5)+1):
                if s % div == 0:
                    divlst.append( div )
                    divlst.append( s // div )
            divlst = sorted( list( set( divlst) ) ) 
            # print("\tdivlst: ", divlst)
            
            for a,b in zip(divlst, divlst[::-1]):
                if a * b == s and a <= b:
                    # print("\t\ta,b: ", a,b)
                    if ( a + b ) % 2 == 0:
                        w = (a+b)//2
                        v = (b-a)//2
                        # print("\t w : ", w, "v: ", v)
                        if   1 <= w <= N and 1 <= v <= N and w == v: 
                            ans += 1
                            # print("ans1 get!")
                        elif 1 <= w <= N and 1 <= v <= N           : 
                            ans += 1
                            # print("ans2 get!")
                    
                else:
                    break

print(ans)


0